Number of windows opened is displayed wrongly | Selenium Forum
M
Posted on 05/09/2016
Hi All,

I have written the below code and I was expecting that in console I should get
Total windows opened: 1
But the result was Total windows opened: 2
Please let me know why its showing Total windows opened: 2 instead of 1

Firefox Version: 48.0.2
OS: Windows 10
Selenium Webdriver: Version 3.0.0

[code:2hlbikbz]import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

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

public class TravelOPod {
public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

Set<String> windowIDs = driver.getWindowHandles();
System.out.println("Total windows opened: "+windowIDs.size());
Iterator<String> it = windowIDs.iterator();
System.out.println(it.next());
System.out.println(it.next());
}
}[/code:2hlbikbz]

M
Replied on 05/09/2016

which website are you opening?


M
Replied on 05/09/2016

I'm not opening any URL.
As only one Firefox browser window tab was opened by using
driver = new FirefoxDriver()
I was expecting [b:2lhtu6gf]Total windows opened: 1[/b:2lhtu6gf].
But its displaying [b:2lhtu6gf]Total windows opened: 2[/b:2lhtu6gf].
Why it so?


M
Replied on 06/09/2016

for me it is working.

[quote:28eg5xec]log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Total windows opened: 1
{b30ec5df-0b8c-49bb-918e-1b2e7d491144}
[/quote:28eg5xec]