The focus of this section
Working with Drop-down boxes
Switch_to_alert ()
Accept ()
Dropdown box is our most common kind of page elements, for the general element, we only need to position once, but the contents of the dropdown box needs to be positioned two times, first navigate to the Drop-down box, and then navigate to the dropdown box in the options.
Drop_down.html
Analytical:
This may be different from the previous operation, first to navigate to the elements of the Drop-down box, and then select the options in the Drop-down list to click.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
m=driver.find_element_by_id ("ShippingMethod")
M.find_element_by_xpath ("//option[@value = ' 10.69 ']"). Click ()
Baidu Search Settings Dropdown box operation
#-*-coding=utf-8 from
Selenium import webdriver
import os,time
driver= webdriver. Firefox ()
driver.get ("http://www.baidu.com")
#进入搜索设置页
driver.find_element_by_link_text ("Search Settings"). Click ()
#设置每页搜索结果为100条
m=driver.find_element_by_name ("NR")
M.find_element_by_xpath ("//option[@ Value= '] ""). Click ()
time.sleep (2)
#保存设置的信息
driver.find_element_by_xpath ("//input[@value = ' Save Settings ']. Click () time.sleep (
2) Driver.switch_to_alert ()
. Accept ()
#跳转到百度首页后, Search table (one page should show 100 results)
driver.find_element_by_id ("kw"). Send_keys ("Selenium")
driver.find_element_by_id ("su"). Click ()
Time.sleep (3)
driver.quit ()
Analytical:
When we save Baidu's settings will pop up a OK button; We did not follow the usual way to locate the "OK" button on the window, but instead use:
Driver.switch_to_alert (). Accept ()
The operation is complete because the window comparison is a unique warning message, so it can be handled in this simple way.
–switch_to_alert ()
A warning (hint) to focus on the page
–accept ()
Accept Warning Tips