First use switch_to.alert () method of positioning, and then use text, accept, dismiss, send_keys like operations.
- text: return text message alert, confirm, prompt in
- accept (): accept the existing alert box
- dismiss (): the dissolution of the existing alert box
- send_key (): Enter the text in the warning box (if you can enter)
Baidu search settings to pop an example:
from Time Import SLEEP from Selenium Import the webdriver 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 ) # save settings driver.find_element_by_class_name ( " prefpanelgo " ) .click () # get the alert box alert =driver.switch_to.alert # acquires warning information alert_text = alert.text Print (alert_text) # acess warning box alert.accept () driver.quit ()
The output is:
It has been recorded under your preferences