How to switch between tabs on a browser and get titles of each tab using Selenium?

0 votes
How to switch between tabs on a browser and get titles of each tab using Selenium?
Jul 22 in Selenium by Abhimanyu
468 views

1 answer to this question.

0 votes

Hi Abhimanyu, you can use following code snippet to switch between tabs on a browser and get titles of each tab using Selenium Webdriver:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Abha_Rathour\\Downloads\\chromedriver_win32\\chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://www.google.com/");

String link = "window.open('https://www.edureka.co','_blank');";

((JavascriptExecutor)driver).executeScript(link);

link = "window.open('https://www.facebook.com','_blank');";

((JavascriptExecutor)driver).executeScript(link);

for (String windowHandle : driver.getWindowHandles()) {

driver.switchTo().window(windowHandle);

System.out.println(driver.getTitle());

Thread.sleep(5000);

}
answered Jul 22 by Abha
• 27,200 points

Related Questions In Selenium

0 votes
5 answers
0 votes
1 answer

How to switch between two windows in browser using Selenium java

Yes, this is possible. First, you need ...READ MORE

answered Sep 25, 2018 in Selenium by Meci Matt
• 9,440 points
4,178 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 12,900 points
849 views
0 votes
1 answer

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,430 points
1,199 views
0 votes
1 answer
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,510 points
1,283 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,510 points
1,041 views
0 votes
1 answer

How to open new tab in same browser and switch between them using Selenium?

Hi Mugdha, you can use following code ...READ MORE

answered May 24 in Selenium by Abha
• 27,200 points
1,539 views
0 votes
1 answer