Webdriver processing of pop-up windows that cannot locate elements

Source: Internet
Author: User

No reprint without the permission of the author!

Sometimes when you open a Web page, a dialog box prompts you to enter a user name and password, only after you enter the correct user name and password

To start browsing the web, but Webdriver cannot locate the elements in this dialog box, which means that the right button on the dialog doesn't respond.

I believe everyone has encountered this problem of the pit father, below provides a simple and effective method!

You can try this page https://www.engprod-charter.net/

Here are the pages to be processed today

ImportOrg.openqa.selenium.WebDriver;ImportOrg.openqa.selenium.chrome.ChromeDriver; Public classwindowDialog20161209 { Public Static voidMain (string[] args)throwsinterruptedexception {//TODO auto-generated Method StubSystem.setproperty ("Webdriver.chorme.driver", "c:\\training\\automation\\software\\drivers\\chromedriver_win32\ \chromedriver.exe "); Webdriver Driver=Newchromedriver ();//Driver.get ("http://test3.tcom.aws.toyota.com/tcom-apps/vapi-preview/console.html");//Thread.Sleep (the);//System.out.println ("User name and password required to open Web page");//driver.close ();Driver.get ("Http://toyota-oss:[email protected]/tcom-apps/vapi-preview/console.html"); Thread.Sleep (3000); Driver.switchto (). alert (). Accept (),------------the default selection of the pop-up window determines System.out.println ("The pop window has been processed."); }}

Here is the Python code

 fromSeleniumImportWebdriverImport Time fromSelenium.webdriver.common.action_chainsImportActionchainsdriver=Webdriver. Chrome () Driver.get ("Http://toyota-oss:[email protected]/tcom-apps/vapi-preview/console.html")#alert = Driver.switch_to_alert () If it is the first time you open the link above, you need to alert.accept (), but after the second time, the cookie will no longer have a popup window.#alert.accept ()Driver.maximize_window () time.sleep (2)Print "go to Toyota home" 


Webdriver processing of pop-up windows that cannot locate elements

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.