Saturday, July 6, 2019

Basic operations in Selenium Python - Part 1

Basic operations in Selenium Python

1. Set value to input textbox

from selenium.webdriver.common.keys import Keys
....
....
# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("mano")

or 

# Set value to Username
driver.find_element_by_name("UserId").send_keys("mano")

2. Set value to input Dropdown or Select input

from selenium.webdriver.support.select import Select
....
....
#Set value to EnterpriseCode
#select by visible text i.e, MYENTS
selectEnterpriseCode = Select(driver.find_element_by_id('EnterpriseCode'))
selectEnterpriseCode.select_by_visible_text('MYENTS')

or 

#Set value to EnterpriseCode
#select by visible text i.e, MYENTS
Select(driver.find_element_by_id('EnterpriseCode')).select_by_visible_text('MYENTS')


3. Click anchor tag or hyperlink using link text

from selenium.webdriver.common.by import By
....
....

#Open Favorite link
driver.find_element_by_link_text('MyFavoriteShipments').click()

#Identify a hyperlink using its href SUBSTRING
#Then click the link
taskid = driver.find_element_by_xpath('//a[contains(@href, "%s")]' % "TaskKey")
taskid.click()


4. Execute script

#Call javascript method i.e, slideSearchPanelView()

driver.execute_script("slideSearchPanelView();")

#Get Dynamic Secure Token or get javascript variable's value
secureToken = driver.execute_script("return sc.csrf.value;")

2 comments:

  1. I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. ้‡‘่žไปฃๅ†™

    ReplyDelete

Popular Posts