Selenium webdriver-operation JavaScript prompt pop-up window (low utilization)

Source: Internet
Author: User

#Encoding=utf-8ImportUnitTestImport Time fromSeleniumImportWebdriver fromSelenium.webdriverImportActionchainsclassVisitsogoubyie (unittest. TestCase):defsetUp (self):#Start IE browser        #self.driver = Webdriver. Firefox (Executable_path = "E:\\geckodriver")Self.driver = Webdriver. Ie (Executable_path ="E:\\iedriverserver")            deftesthandleprompt (self): URL="http://127.0.0.1/test_prompt.html"        #Accessing a custom Web pageself.driver.get (URL)#Locate the unique button element on the page being tested using the ID Locator methodelement = self.driver.find_element_by_id ("Button") Element.click () Time.sleep (2)        #click the button element to bring up a prompt prompt box,        #The above will show "This is a prompt popup", the input box,        #OK button and Cancel button        #Use the Driver.switch_to_alert () method to get the Alert objectAlert =Self.driver.switch_to.alert#use the Alert.text method to get the text above the prompt box,        #and assert that the text content is consistent with "This is a prompt popup"Self.assertequal (U"This is a prompt pop-up box", Alert.text) time.sleep (1)        #Call the Alert.send_keys () method and enter it in the input box of the prompt form        #"The Road to glory: To change your destiny, you must study 2 hours a day!" "Alert.send_keys (U"The Road to glory: To change your destiny, you must study 2 hours a day! ") Time.sleep (1)        #using the Accept method of the Alert object,        #Click the "OK" button in the prompt box to close the prompt boxalert.accept ()#using the dismiss method of the Alert object, click the Cancel button on the prompt box to close the prompt box        #canceling the comment on the following line of code simulates clicking the Cancel button on the prompt box        #Alert.dismiss ()    defTearDown (self):#Exit IE Browserself.driver.quit () unittest.main ( )

Selenium webdriver-operation JavaScript prompt pop-up window (low utilization)

Related Article

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.