As shown, this window can not be positioned through the front-end tool, where the Switch_to_alert () method to accept the pop-up window
1 #coding = Utf-82 3 fromSeleniumImportWebdriver4 fromSelenium.webdriver.common.action_chainsImportActionchains5 Import Time6 7Dr =Webdriver. Firefox ()8Dr.get ("http://www.baidu.com")9 Ten #hover over the settings link One #link = dr.find_element_by_link_text ("set") #这方法定位不了, but only by XPath Alink = dr.find_element_by_xpath ("/html/body/div[1]/div[1]/div/div[3]/a[8]") - Actionchains (DR) move_to_element (link). Perform () -Time.sleep (5) the - #Open Search Settings -Dr.find_element_by_link_text ("Search Settings"). Click () -Time.sleep (5) + - #Save Settings +Dr.find_element_by_class_name ("Prefpanelgo"). Click ()#This is the class of the Save button ATime.sleep (5) at - #Accept the warning box - Dr.switch_to_alert (). Accept () - -Dr.quit ()
Switch_to_alert (). Accept () accepted window existing warning box
Switch_to_alert (). Text () Returns the text information of the window
Switch_to_alert (). Dissmiss () Dissolve an existing warning box
Switch_to_alert (). Send_keys (Keystosend) sends the text to the warning box. Keystosend: Send text to Warning box # I don't understand what keystosend is.
Python+selenium Learning note 9-warning box handling