WebDriver alert box handle --- (Mushishi "selenium3 automated testing combat - based on the Python language note 20")

First use switch_to.alert () method of positioning, and then use text, accept, dismiss, send_keys like operations.

  1. text: return text message alert, confirm, prompt in
  2. accept (): accept the existing alert box
  3. dismiss (): the dissolution of the existing alert box
  4. 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

 

Guess you like

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