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
31 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
• 19,130 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,400 points
2,533 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,200 points
169 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,050 points
403 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,130 points
758 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,130 points
400 views
0 votes
1 answer
0 votes
1 answer