WebDriver drop-down box handle --- (Mushishi "selenium3 automated testing combat - based on the Python language note 21")

Providing WebDriver Select category drop-down box process.

  • Select class: for positioning <select> tag
  • select_by_value: by value value targeting drop-down option
  • select_by_visible_text (): text value by positioning the drop-down option
  • select_by_index (): to select the index drop-down options. The first option is 0, the second option 1
from Time Import SLEEP
 from Selenium Import the webdriver
 from selenium.webdriver.support.select Import the Select 

Driver = webdriver.Chrome () 
driver.get ( " http://www.baidu.com " ) 

# Open Search Set 
link = driver.find_element_by_link_text ( " settings " ) .click () 
driver.find_element_by_link_text ( " search settings " ) .click () 
SLEEP ( 2 ) 

# search result display number of 
SEL = driver.find_element_by_xpath ( "SELECT // [@id = 'NR'] " ) 

# value =" 20 is " 
the Select (SEL) .select_by_value ( " 20 is " ) 
SLEEP ( 2 ) 

# <Option> per page 50 </ Option> 
the Select (SEL ) .select_by_visible_text ( " per page 50 " ) 
SLEEP ( 2 ) 

driver.quit ()

 

Guess you like

Origin www.cnblogs.com/kite123/p/11511575.html