I am trying to change my driver's focus to the new window that pops up as a result of clicking a link. The only problem is that both the parent window and the pop-up window have the same handle - for example - the title of both is " <Company Name - Abbreviation 1>
How would I use Selenium JAVA to get focus on the pop-up window a different way than what I have used?
`
String originalWindow = driver.getWindowHandle();
assert driver.getWindowHandles().size() == 1; driver.findElement(By.xpath("xpath goes here")).click(); // Training
// Loop through until we find a new window handle
for (String windowHandle : driver.getWindowHandles()) {
if (!originalWindow.contentEquals(windowHandle)) {
driver.switchTo().window(windowHandle);
driver.manage().window().maximize();
}
}
`
Thanks, Everyone!
`
String originalWindow = driver.getWindowHandle();
assert driver.getWindowHandles().size() == 1;
driver.findElement(By.xpath("xpath goes here")).click(); // Training
Thread.sleep(1000);
// Loop through until we find a new window handle
for (String windowHandle : driver.getWindowHandles()) {
if (!originalWindow.contentEquals(windowHandle)) {
driver.switchTo().window(windowHandle);
driver.manage().window().maximize();
}
}
`
I tried the above code, but both windows sadly have the same title. I want to switch focus to the new window so I can then interact with the new one.