Switching between tabs
Switching between tabs in same browser window
driver.get("http://google.com"); String windowHandle = driver.getWindowHandle(); driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
The size of the output of getWindowHandles() is 1 which means that there is one single window handle
ArrayListtabs = new ArrayList (driver.getWindowHandles()); System.out.println(tabs.size()); driver.switchTo().window(tabs.get(0));
The control is now in the new tab
driver.get("http://bing.com"); //perform other operations.
Switch to the old tab using Ctrl + Tab
driver.switchTo().window(mainWindowHandle); driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t"); driver.switchTo().defaultContent();
Comments
Post a Comment