Java Selenium (12) Operation Popup window

Source: Internet
Author: User

How to handle popup windows in Selenium

Read Catalogue

Principle

In the code, through set<string> allwindowsid = Driver.getwindowhandles ();

To get a handle to all pop-up browsers, and then traverse through, using the Swithcto.window (Newwindow_handle) method. You can navigate to the new window.

HTML of the test page
<HTML><Head>    <title>Common Web UI element operations, and API usage</title>    <Scripttype= "Text/javascript">        functionOpen_win () {window.open ("http://www.cnblogs.com")        }    </Script></Head><Body>    <form>        <inputtype=buttonvalue= "open Window"onclick= "Open_win ()">    </form>    </Div></Body></HTML>

Java Code
Public static void Testmultiplewindowstitle (Webdriver driver) throws Exception {String url= "e:\\stashfo        Lder\\[email protected]\\stash\\tank-moneyproject\\selenium webdriver\\alluielement.html ";        Driver.get (URL);        Gets the handle of the current window, String Parentwindowid = Driver.getwindowhandle ();                System.out.println ("Driver.gettitle ():" + driver.gettitle ());        Webelement button = driver.findelement (By.xpath ("//input[@value = ' open Window ']");                Button.Click (); Set<String>Allwindowsid = Driver.getwindowhandles (); Gets all open window handles for (String windowid:allwindowsid) {if (Driver.switchto (). window (Windowid). GetTitle ()                . Contains ("blog Park")) {Driver.switchto (). window (WINDOWID);            Break                }} System.out.println ("Driver.gettitle ():" + driver.gettitle ());        Switch back to the original parent window Driver.switchto (). Windows (PARENTWINDOWID);    System.out.println ("Parentwindowid:" + driver.gettitle ()); }

Java Selenium (12) Operation Popup window

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.