Switch between different tabs in a browser (firefox)

150 views
Skip to first unread message

Bipin Kuriakose

unread,
Nov 19, 2014, 7:13:43 AM11/19/14
to seleniu...@googlegroups.com
Hello, is there a way to switch between different tabs in firefox using the page title? 

Lets say, i have www.google.com and www.yahoo.com tabs open in my firefox. I need to switch between these two based on the page title names "Google" and "Yahoo" ? 

Any best approach in selenium?

Moath

unread,
Nov 20, 2014, 7:53:33 AM11/20/14
to seleniu...@googlegroups.com
You can move through them by the tab ID, the tabs ordering saved in array and you can move through these tabs by calling the array number for the required tab. Do you want example?
Thanks

--
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/msgid/selenium-users/0e1ff1e6-37ce-4b63-a924-bd1d08baa94d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Narendra Kumar Singh

unread,
Nov 20, 2014, 8:00:16 AM11/20/14
to seleniu...@googlegroups.com

Yes, you can use window ids to switch to different tab/window.

1. First get all the window handles.
2 Store the window ids in variable.
3. Switch to specific window id.
4. Now control moves to specified window ids tab.

Note: Once ur operations gets completed don't forget to switched back to main window.

Thanks and Regards,
-Narendra Singh

Elumalai V

unread,
Nov 21, 2014, 12:33:09 AM11/21/14
to seleniu...@googlegroups.com
Please give me a code.I'm waiting

Elumalai V

unread,
Nov 21, 2014, 12:34:15 AM11/21/14
to seleniu...@googlegroups.com
Please give a code .

Sourabh Das

unread,
Nov 26, 2014, 1:38:40 PM11/26/14
to seleniu...@googlegroups.com
Case 1:
You can use getWindowHandle API to get the window handle of the tabs and then use switchTo API to switch between them. But this approach is useful if you have the two pages opened in different windows.
Sample code:
String parentHandle = driver.getWindowHandle();
List<String> windowHandles = driver.getWindowHandles();
//Switching between handles
for(String handle : windowHandles) {
    driver.switchTo.window(windowHandles.get(i));
}
//Switch back to the parent handle.
driver.switchTo.window(parentHandle);

Case 2:
If you have the pages opened in different tabs in the same window, then the above approach does not help as in this case there is only one window handle and hence switchTo(String windowHandle) API does not help.
In this case, the following approach seems to work:
1. Open the new tab using Ctrl + t
2. Switch between the tabs using Ctrl + \t (Ctrl + Tab)
Detailed sample code can be found here: http://design-interviews.blogspot.com/2014/11/switching-between-tabs-in-same-browser-window.html


On Wednesday, November 19, 2014 5:43:43 PM UTC+5:30, Bipin Kuriakose wrote:
Reply all
Reply to author
Forward
0 new messages