Selenium Videos - Module 14 Handling multiple tabs | Selenium Forum
M
Posted on 05/09/2016
Hi Ashish,

The technique explained to handle multiple tabs is not seems to be working. I have the below code where there are 2 tabs opened in the browser but still the number of tabs opened is displayed as 1 instead of 2. Could you please help on the same.

[code:1dmb0akp]import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail {
public static void main(String[] args){
//type, clear, read
System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/gmail/about/");
String currentWindow = driver.getWindowHandle();
System.out.println(currentWindow);
driver.findElement(By.linkText("Sign In")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Set<String> windowIDs = driver.getWindowHandles();
System.out.println("The number of tabs opened: "+windowIDs.size());
//driver.close();
//driver.quit();
}
}
[/code:1dmb0akp]

M
Replied on 05/09/2016

send a screen shot.


M
Replied on 05/09/2016

Find the screen shot attached.


M
Replied on 05/09/2016

it is opening one tab for me.

Responsive image

M
Replied on 06/09/2016

Again I'm clicking on the 'Sign In' link. Which will open another tab.


M
Replied on 06/09/2016

Here all I want to navigate to the new opened tab and do some actions and close that newly opened tab and navigate back to the original tab. How can I do that?


M
Replied on 06/09/2016

use some other website there is some problem with your computer or gmail.

[quote:1x50mkw1]How can I do that?[/quote:1x50mkw1]
windows handle. as far as i know there is no other way.