Python+selenium Learning note 9-warning box handling

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.