python + selenium alter the pop object processing 02


First, using switch_to.alert () method to locate, and then can use the following operations

text: return alert, confirm, the text message prompt;

Accept (): accept the existing alert box;

Dismiss (): dissolution of existing alert box;

send_keys (): in the text box warning (if entered);



--------------------------------- -------------------------------------------------- ----

from the Selenium Import webdriver
from selenium.webdriver.common.action_chains Import ActionChains
from Time Import SLEEP


Driver = webdriver.Firefox () # specify and open a browser
driver.get ( 'http://www.baidu.com' )


Link = driver.find_element_by_link_text ( "settings")
ActionChains (Driver) .move_to_element (Link) .perform () # hover above
SLEEP (5)
driver.find_element_by_class_name ( "setpref"). the click () # click advanced Search

sleep (5)
driver.find_element_by_class_name ( 'prefpanelgo'). click () # Click Save


sleep (5)
Content print (driver.switch_to.alert.text) # get a warning is printed inside the box

sleep (5)
driver.switch_to.alert.accept () # click OK

SLEEP (5)
driver.close ()

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12041030.html