Module 14 - output for window handle is -1,-2 | Selenium Forum
M
Posted on 20/04/2016
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;

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

public class Rediff {

public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(15,TimeUnit.SECONDS);

Set<String> windowIds =driver.getWindowHandles();;
System.out.println("Total Window Opened: -"+windowIds.size());
Iterator<String> it = windowIds.iterator();
System.out.println(it.next());

System.out.println("---------------------");
driver.get("http://www.rediff.com/");
windowIds =driver.getWindowHandles();
System.out.println("Total Window Opened: -"+windowIds.size());
it = windowIds.iterator();
System.out.println(it.next());
System.out.println(it.next());
}

}
==========================================
OUTPUT I received

Total Window Opened: -1
{94b375b5-cddf-45f2-a5af-d94195cc9cab}
---------------------
Total Window Opened: -2
{94b375b5-cddf-45f2-a5af-d94195cc9cab}
{c7603b59-d426-48f5-93d0-247204b2bdeb}

M
Replied on 20/04/2016

what is the problem?


M
Replied on 20/04/2016

why result is "Total Window Opened: -1 & -2" ?

video session result is displayed "Total Window Opened: 1,2"


M
Replied on 20/04/2016

i'm still not able to understand.

it is showing 2 because there must be 2 windows open.


M
Replied on 21/04/2016

my query is

why output is -1 instead of 1, -2 instead of 2 ?

why result is "Total Window Opened: -1 & -2" ?


M
Replied on 23/04/2016

Hi,

is this resolved?

It is printing Window size as 1 & 2 only. It just because in your print statement you had mentioned "-" as below which is showing as negative (-1 & -2).

System.out.println("Total Window Opened: -"+windowIds.size());