Generally it comes the scenario when on clicking an element in Web Application results in opening a a new tab.
We can focus on the newly opened tab using the following snippet
String oldTab = driver.getWindowHandle();
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
newTab.remove(oldTab);
// change focus to new tab
driver.switchTo().window(newTab.get(0));
assertEquals("java - Google Search", driver.getTitle());// expected,actual
We can focus on the newly opened tab using the following snippet
String oldTab = driver.getWindowHandle();
ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
newTab.remove(oldTab);
// change focus to new tab
driver.switchTo().window(newTab.get(0));
assertEquals("java - Google Search", driver.getTitle());// expected,actual
No comments:
Post a Comment