Reputation: 11
I used below code to open the new tab..but it is not working.. can someone help, is there any other way to do this?
Robot rr= new Robot();
rr.keyPress(KeyEvent.VK_CONTROL);
rr.keyPress(KeyEvent.VK_T);
rr.keyRelease(KeyEvent.VK_CONTROL);
rr.keyRelease(KeyEvent.VK_T);
Set<String> allWindows=driver.getWindowHandles();`enter code here`
System.out.println(allWindows);
List<String> list=new ArrayList<String>();
driver.switchTo().window(list.get(1));
driver.get("url");
Upvotes: 0
Views: 147
Reputation: 597
String parentWindowHandler=driver.getWindowHandle();// Store your parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // Switch to new tab
Upvotes: 0
Reputation: 732
You can use Javascript executor for opening a new tab in the same window.Please follow the approach mentioned below:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.open();");
I have tried it on my MAC machine and it is working as expected.
Upvotes: 1