I'm automating a portal using selenium web driver + Internet Explorer, was able to open a multiple new tabs on existing window but was not able to pass URL to newly opened tab, IE isn't recognizing new tabs and getWindowHandles() returns count as 1, the same code works fine with Chrome.
Sample Code 1 :
String baseUrl = "www.facebook.com";
driver.get(baseUrl);
driver.findElement(By.xpath("//*[@id='userName']")).sendKeys("xyz");
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("****");
driver.findElement(By.xpath("//*[@id='loginButton']")).click();
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL +"t");
driver.getWindowHandles();
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(1)); //switches to new tab
driver.get("www.google.com");
Sample Code 2 :
String baseUrl = "www.facebook.com";
driver.get(baseUrl);
driver.findElement(By.xpath("//*[@id='userName']")).sendKeys("xyz");
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("****");
driver.findElement(By.xpath("//*[@id='loginButton']")).click();
String parent = driver.getWindowHandle();
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL +"t");
Thread.sleep(3000);
for(String winHandle : driver.getWindowHandles()){
if(!winHandle.equals(parent)){
driver.switchTo().window(winHandle);
driver.get("www.google.com");
}
}
Also tried several other ways changing IE configuration like changing protected modes/Overriding automatic cookie handling but nothing worked.
Is there a way to open new tab in IE via code and get the accurate tab count using any method in Selenium?
Configuration:
IE :11,
Selenium-java : 2.47/3.7
IEDriver : 3.3.0/2.53,
Windows 7
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…