How to handle pop-up windows in selenium
Reading Table of Contents
- Principle
- To test the HTML of a page
- 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!