How to switch tabs using Selenium WebDriver with Java

0 votes
Using Selenium WebDriver with JAVA. I am trying to automate a functionality where I have to open a new tab do some operations there and come back to previous tab (Parent). I used switch handle but it's not working. And one strange thing the two tabs are having same window handle due to which I am not able to switch between tabs.

However when I am trying with different Firefox windows it works, but for tab it's not working.

Please help me. How can I switch tabs. OR how can I switch tabs without using window handle as window handle is same of both tabs in my case.
Dec 3, 2020 in Selenium by anonymous
• 8,910 points
4,772 views

1 answer to this question.

0 votes
psdbComponent.clickDocumentLink();
    ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
    driver.switchTo().window(tabs2.get(1));
    driver.close();
    driver.switchTo().window(tabs2.get(0));

This code perfectly worked for me. Try it out. You always need to switch your driver to a new tab, before you want to do something on a new tab.

For more, go for the Selenium Certification Course and become a certified.

Thanks!

answered Dec 3, 2020 by Gitika
• 65,910 points

Related Questions In Selenium

+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,955 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,489 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,236 views
+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
194,151 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,714 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,683 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
0 votes
1 answer
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 14, 2020 in Selenium by Gitika
• 65,910 points
101,605 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP