Switch to main/default window.

2,099 views
Skip to first unread message

Sudhansu Sekhar panda

unread,
Apr 18, 2013, 1:01:34 AM4/18/13
to seleniu...@googlegroups.com
Hi All,

Please explain me in the below scenario.

Scenario: 

Clicking on a link, the link is opening in a new window. For performing some operation(i.e giving control to the new window) on the new window i am using the switchToWindow() method. After performing certain operation  i am closing the new window by using driver.close(). After that i am able to perform everything in the main window without using the switchingToDefaultWindow() method for giving  the control back to the main window. 




Queries:

1. Where should the control present in the main window or in the new window?

2. How am i able to perform anything in the main window even if i am not using switchToDefaultWindow() method?

3. Should  i able to perform any operation on the main window without the use of switchingToDefaultWindow()?

4. The moment when  i will close the new window where actually my control will present i.e in the new window or in the main window?

Thanks

Sudhansu


Justin Gourley

unread,
Apr 18, 2013, 11:38:01 AM4/18/13
to seleniu...@googlegroups.com
Any time a new window is opened, before working in that window you will need to switch to it. You can accomplish this with: driver.switchTo().window(newestWindowName)

Once you have switched to a new window (or frame), you can switch back to your original window(or frame) with this code: driver.switchTo().defaultContent()

Note, that you can also switch back to your original window with the code:  driver.switchTo().window(originalWindowName)  


Hope this clarifies some of your queries!




Sudhansu


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/uJ3PD0BSOzQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sudhansu Sekhar panda

unread,
Apr 19, 2013, 5:47:34 AM4/19/13
to seleniu...@googlegroups.com
Hi Jaustin,

I understood what you are trying to explain. But 

Am i able to perform anything in the main window even if i am not using switchToDefaultWindow() method? 

That means without coming to default window how can i able to perform anything?

This is my question in fact.

Vivek Mishra

unread,
Apr 19, 2013, 7:31:27 AM4/19/13
to seleniu...@googlegroups.com
Hey Sudhansu,
 
Replies to your queries:-
 
1. Main Window (Parent Window)
2. If you are using driver.close() method, control automatically goes to Parent Window, But it is advisable to use either switchToDefault or switchToWindow .
3. yes, if you are using driver.close(), but if you are closing the pop up window (by clicking the cross button or close button in window itself, i think it is mandatory to use swith commands) ,but better you use switch in all scenarios .
4. I think this is ur first query .
 
Thanks
Vivek



Sudhansu


Jim Evans

unread,
Apr 19, 2013, 8:40:10 AM4/19/13
to seleniu...@googlegroups.com
No, I'm sorry, but there is some serious misinformation being disseminated in this thread. If you have a web application that uses multiple browser windows, you must switch WebDriver's "focus" between those windows. In Java, you do this by driver.switchTo().window(). When you close any of your browser windows using driver.close(), you *must* use driver.switchTo().window() to put that focus on another window. WebDriver has *no* concept of a "main" window to switch focus back to.

Using driver.switchTo().defaultContent() *only* has meaning for frames/iframes. It puts the frame focus within a window to the top-level frame in the window. It has no effect on which browser window is being actively manipulated.

Justin Gourley

unread,
Apr 19, 2013, 10:38:53 AM4/19/13
to seleniu...@googlegroups.com
My fault for a misread on the docs :( Apologies.


On Fri, Apr 19, 2013 at 5:40 AM, Jim Evans <james.h....@gmail.com> wrote:
No, I'm sorry, but there is some serious misinformation being disseminated in this thread. If you have a web application that uses multiple browser windows, you must switch WebDriver's "focus" between those windows. In Java, you do this by driver.switchTo().window(). When you close any of your browser windows using driver.close(), you *must* use driver.switchTo().window() to put that focus on another window. WebDriver has *no* concept of a "main" window to switch focus back to.

Using driver.switchTo().defaultContent() *only* has meaning for frames/iframes. It puts the frame focus within a window to the top-level frame in the window. It has no effect on which browser window is being actively manipulated.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/dwDYnExeuKsJ.

Manoj Hans

unread,
Apr 22, 2013, 9:17:52 AM4/22/13
to seleniu...@googlegroups.com
@Jim-- +1

Bhaskar B.V

unread,
Sep 19, 2018, 4:29:21 PM9/19/18
to Selenium Users
Nicely explained Jim Evas..! what you said is 100 pc correct. Yes some false info trolled in this group.
I tried defaultContent for windows but it is not working for windows.
Thanks for the valuble info.
Reply all
Reply to author
Forward
0 new messages