Selenium-webdriver drop-down box processing select

For the <select> tag, the following methods can be used:

  • select_by_value () locates drop-down options by value
  • select_by_index () through the index position of the drop-down option, starting from 0
  • select_by_visible_text () locates by text value

 

The Baidu search drop-down box is as follows:

 

 Choose to display 20, 10, and 50 on each page:

 1 from selenium import webdriver
 2 import time
 3 from selenium.webdriver.support.select import Select
 4 
 5 driver = webdriver.Chrome()
 6 driver.maximize_window()
 7 driver.get('http://www.baidu.com')
 8 
 9 driver.find_element_by_link_text('设置').click()
10 driver.find_element_by_link_text('搜索设置').click()
11 time.sleep(2)
12 is  
13 is SEL = driver.find_element_by_id ( ' NR ' )   # targeting SELECT 
14  
15 the Select (SEL) .select_by_value ( ' 20 is ' )      # drop-down list 
16 the time.sleep (2 )
 . 17 the Select (SEL) .select_by_index (0)    # selection drop-down list, the first 
18 is the time.sleep (2 )
 . 19 the select (SEL) .select_by_visible_text ( ' per page 50 ' )    # drop-down list 
20 is the time.sleep (2 )
 21 is  
22 is driver.quit ()

 

Guess you like

Origin www.cnblogs.com/xiaochongc/p/12708269.html