Help with winhandles

48 views
Skip to first unread message

Forged

unread,
Sep 25, 2014, 12:37:27 AM9/25/14
to seleniu...@googlegroups.com
Hi,

I'm new to selenium (new to java) and I'm having problems switching from one window to another. 

We are currently testing an IE based application, the behavior of this system is once a button is clicked, it opens a new window and closes the old one automatically. Most of the guides I found on google involves multiple windows that are simultaneously open and this is not the case with the system i am testing.

I have tried the following code after the button for opening the new window is clicked:

String winhandlenew = driver.getWindowHandle();
driver.switchTo().window(winhandlenew);

the commands themselves do not give any error but as i progress, every element on that new window cannot be found. So, basically I have no clue if I need to switch windows, if I'm switching correctly or if the xpath for the element on this new window is incorrect. 

Thanks in advance!

Andreas Tolfsen

unread,
Sep 25, 2014, 5:46:37 AM9/25/14
to seleniu...@googlegroups.com
On Thu, Sep 25, 2014 at 5:37 AM, Forged <andrew....@gmail.com> wrote:
> We are currently testing an IE based application, the behavior of this
> system is once a button is clicked, it opens a new window and closes the old
> one automatically. Most of the guides I found on google involves multiple
> windows that are simultaneously open and this is not the case with the
> system i am testing.
>
> I have tried the following code after the button for opening the new window
> is clicked:
>
> String winhandlenew = driver.getWindowHandle();
> driver.switchTo().window(winhandlenew);

Windows can be switched to by either name or handle. The name is the
explicit name given to it when doing window.open(url, name). Handles
are UUID's that WebDriver add to make each window uniquely accessible
in the event that they don't have explicit names.

Because the window context you're in when you click the button
disappears WebDriver shouldn't continue on as it looses its default
content. In other words, there is no active document it can operate
within.

Nonetheless it might still work in some drivers to switch to another window:

driver.switchTo().window("name of window");

Or if you don't know the name you need to find the new window handle
from driver.getWindowHandles().

Harsh Ma

unread,
Sep 25, 2014, 6:59:32 AM9/25/14
to seleniu...@googlegroups.com
Are u sure if u wana switch b/w windows / Frames!!
make that clear because as a beginner we should be clear on that (as i was not in the beginning states of Automation :D)

I feel u would like to switch b/w frames check the link:
http://jathinmallya.wordpress.com/2014/08/18/switch-between-frames-using-webdriver/
Message has been deleted

Sudhansu Sekhar panda

unread,
Sep 25, 2014, 7:02:45 AM9/25/14
to seleniu...@googlegroups.com
Hi,

Can you try the below code using WindowHandles to switch the currently active Window...

// Get all the window handles one by one
 
for (String windowHandle: driver.getWindowHandles())
 
{


 driver
.switchTo().window(windowHandle);
 
 
 
}



Thanks,

Sudhansu,

Sudhansu Sekhar panda

unread,
Sep 25, 2014, 11:01:20 AM9/25/14
to seleniu...@googlegroups.com
Hi,

Does this solve your problem?

Thanks,

Sudhansu

Mukesh otwani

unread,
Sep 25, 2014, 3:10:10 PM9/25/14
to seleniu...@googlegroups.com
Hi ,

Try this code and if you face any issue please let me know

http://www.learn-automation.com/2014/06/how-to-handle-multiple-window-in.html


On Thursday, September 25, 2014 10:07:27 AM UTC+5:30, Forged wrote:
Reply all
Reply to author
Forward
0 new messages