For automation purposes, I am working on creating a script that finds a row in a table. This row is clickable and opens a new tab/adress.
With selenium, I am now able to find the table row, click on the link, and the new tab opens. The problem is that I can't find any way to switch the focus to the newly opened tab. I tried to get all windowHandles and see if I could switch, but even after the new tab has opened, there is only 1 windowHandle.
Below is my code:
WebElement tableRow=driver.findElement(By.xpath("/html/body/div[1]/table/tbody/tr[2]"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", tableRow);
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
The Arraylist always contains 1 single windowHandle, not 2. So I am not able to switch focus to the new tab. Is there any way to solve this?