Java Selenium Action pop-up window sample code _java

Source: Internet
Author: User

How to handle pop-up windows in selenium

Reading Table of Contents

    1. Principle
    2. To test the HTML of a page
    3. Java Code

Principle

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

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

To test the HTML of a page

 
 

Java Code

 public static void Testmultiplewindowstitle (Webdriver driver) throws Exception {String ur
    L= "E:\\stashfolder\\huoli_28@hotmail.com\\stash\\tank-moneyproject\\selenium Webdriver\\AllUIElement.html";
    Driver.get (URL);
    Gets the handle String Parentwindowid = Driver.getwindowhandle () of the current window;
    
    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 the handle for all open windows for (String windowid:allwindowsid) {if Driver.switchto (). window (Windowid). GetTitle (). contain
        S ("blog Park")) {Driver.switchto (). window (WINDOWID);
      Break
    
    } System.out.println ("Driver.gettitle ():" + driver.gettitle ());
    Switch back to the original parent window again Driver.switchto (). window (PARENTWINDOWID);
  System.out.println ("Parentwindowid:" + driver.gettitle ()); }

The above is about the Java Selenium Operation window Windows example, follow-up to continue to collate relevant information, thank you for your support!

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.