0

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.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Reema
  • 5
  • 1
  • 4
  • Switch to that window handle by `driver.switchTo().window("handle");` where `handle` is you get by `driver.getWindowHandle();`. Proceed there after.After you hit 'ok' then `driver.switchTo.defaultContent();` – nitin chawda Mar 17 '15 at 13:00
  • I did get that , but just want to know how what the code would be to click OK on the Window Pop up. I am new to JAVA too, so i am confused about this! – Reema Mar 17 '15 at 17:29

3 Answers3

1

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();
Vivek Singh
  • 3,641
  • 2
  • 22
  • 27
0

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

Community
  • 1
  • 1
DRVaya
  • 443
  • 4
  • 13
0

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.

Mike Weber
  • 311
  • 2
  • 16