0

I am using selenium Java. I need to open new tab and open URL in the newly opened tab. I am try to using getWindowHandles, its working fine in google chrome, but the same code is not working for Internet Explorer. Please suggest the proper solution for this. Here is the code I have used.

WebDriver=new InternetExplorerDriver();
driver.get("https://google/com");
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"t");// Open new tab
driver.switchTo().window(driver.getWindowHandles().iterator().next());
driver.get("http://msn.com");

I also tried following code, but not working.

ArrayList<String> tabs= new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(index));

Note: The same code working fine with google chrome, not working in IE only. IE version:IE10

Chandra Shekhar
  • 664
  • 2
  • 9
  • 24
Sunil Prabakar
  • 442
  • 1
  • 5
  • 19
  • IE is not picking the new tab as a window handle. – Chandra Shekhar Oct 13 '16 at 09:25
  • then we are not able to handle tab in IE, right? – Sunil Prabakar Oct 13 '16 at 09:26
  • After trying in many ways and googling this is what I got to open a new URL in IE, `driver.get("https://www.google.com"); driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"n");// Open new tab driver.switchTo().window(driver.getWindowHandles().iterator().next()); driver.get("http://www.msn.com");` And I suggest you to complete the operations in first window and go to new one as we cannot switch back to the old ones. – Chandra Shekhar Oct 13 '16 at 10:10
  • I already tried with new window alos. actually while opening in new window, the same URL open in new window, while redirecting to new URL old window only getting redirected. Two windows have same URL (Google.com) at initially, it seems new url open in newly created tab. But actually ew URL opened in old window only – Sunil Prabakar Oct 13 '16 at 10:15
  • [check this](http://superuser.com/questions/69857/how-do-i-get-ie8-to-open-a-blank-page-with-ctrl-n) – Chandra Shekhar Oct 13 '16 at 11:03

0 Answers0