three popup alert (one button), confirm (two Ack, cancel), Prompt (two buttons + input box).
Switch to Bullet box: Switch_to_alert ()
How to play the box:
1 text Get bullet box
2 Accept () Confirmation
3 Dimiss () Cancel
4 Send_keys () Prompt the bullet box to enter characters. Two other kinds of errors
The sample script is as follows:
#Coding=utf-8#Pop-up box action fromSeleniumImportWebdriverImportTimedr=Webdriver. Firefox () Dr.get ("https://www.baidu.com")#hidden elements need to be displayed in order to operateSetMenu = Dr.find_element_by_link_text ("Set") Webdriver. Actionchains (DR) Move_to_element (SetMenu). Perform () Dr.find_element_by_link_text ('Search Settings'). Click () time.sleep (3)#elements that are not hidden can be directly selected, and comments out of the parent element to find descendants or#Nrset = dr.find_element_by_id ("nr")#nrset.find_element_by_css_selector ("option[value="). Click ()Dr.find_element_by_css_selector ("option[value= ' []"). Click ()#pop-up box confirms three popup alert (one button), confirm (two buttons), Prompt (two buttons + input box)Dr.find_element_by_link_text ("Save Settings"). Click ()Print(Dr.switch_to_alert (). Text) Dr.switch_to_alert (). Accept ()#Confirm#Dr.switch_to_alert (). Dismiss () #取消#Dr.switch_to_alert (). Send_keys ("Only valid for Prompt") #在弹出框输入内容Time.sleep (2) Dr.quit ()
Selenium Getting Started 10 popup box processing