简体   繁体   中英

Handle Window Pop Up in Selenium

I am working with Selenium, now there is a condition:

when I hit a button in my webpage a window pop up opens up.

Now I have to click a radio button (one out of two, it will work even if we send a TAB ) and then click an OK button. I searched in the net and got to know about " driver.getWindowHandle() ".

But I don't have any idea dealing with the newly opened window popup. Need help in this.

For switching purpose u can use enhanced for loop:

for (String winHandle : objDriver.getWindowHandles()) {
    objDriver.switchTo().window(winHandle);
}

So it will switch the control from one driver window to child windows.

To interact with elements on the window try to find element with whatever tool ur using and perform the required action after switching to the window .

To return back to parent window you can use the same loop or use:

driver.switchTo().defaultContent();

Check my answer in this post and also read the comments to help you understand the difference between getWindowHandle() and getWindowHandles()

Java: focus is not on pop-window during window handling

We handled this situation using AutoItX - https://www.autoitscript.com/site/ in our Windows/IE C# project:

AutoItX3 autoIt = new AutoItX3();
var handle = autoIt.WinWaitActive("[window title]", "", 20);
Assert.IsTrue(handle != 0", string.Format("Was not able to find: {0}", [window title]);
autoIt.Send("{ESCAPE}"); // tab may work as well for selection

The pop up was a Windows window, and not part of IE, therefore the WebDriver didn't know about it. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM