Reema
Reema

Reputation: 5

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.

Upvotes: 0

Views: 7126

Answers (3)

Vivek Singh
Vivek Singh

Reputation: 3649

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 u r 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();

Upvotes: 1

Mike Weber
Mike Weber

Reputation: 311

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.

Upvotes: 0

DRVaya
DRVaya

Reputation: 443

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

Upvotes: 0

Related Questions