Selenium Getting Started 10 popup box processing

Source: Internet
Author: User

three popup alert (one button), confirm (two Ack, cancel), Prompt (two buttons + input box). Switch to Bullet box: Switch_to_alert () How to play the box: 1 text Get bullet box 2 Accept () Confirmation 3 Dimiss () Cancel 4 Send_keys () Prompt the bullet box to enter characters. Two other kinds of errors

The sample script is as follows:

#Coding=utf-8#Pop-up box action fromSeleniumImportWebdriverImportTimedr=Webdriver. Firefox () Dr.get ("https://www.baidu.com")#hidden elements need to be displayed in order to operateSetMenu = Dr.find_element_by_link_text ("Set") Webdriver. Actionchains (DR) Move_to_element (SetMenu). Perform () Dr.find_element_by_link_text ('Search Settings'). Click () time.sleep (3)#elements that are not hidden can be directly selected, and comments out of the parent element to find descendants or#Nrset = dr.find_element_by_id ("nr")#nrset.find_element_by_css_selector ("option[value="). Click ()Dr.find_element_by_css_selector ("option[value= ' []"). Click ()#pop-up box confirms three popup alert (one button), confirm (two buttons), Prompt (two buttons + input box)Dr.find_element_by_link_text ("Save Settings"). Click ()Print(Dr.switch_to_alert (). Text) Dr.switch_to_alert (). Accept ()#Confirm#Dr.switch_to_alert (). Dismiss () #取消#Dr.switch_to_alert (). Send_keys ("Only valid for Prompt") #在弹出框输入内容Time.sleep (2) Dr.quit ()

Selenium Getting Started 10 popup box processing

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.