getWebDriver() doesn’t return the current active web driver when application opens in more than one tabs

On Chrome I am testing an application that opens a new tab after double click. When I use getWebDriver to get the current active driver in the new tab, it returns the old inactive driver, as such I’m running out of ideas to verify objects on the new active tab. Any suggestions on what is happening here?

Hi Japheth,

If you don’t want to use our provided keyword, you can get the driver and interact with it in your own way. Below is an approach to switch to the newest window using Selenium, hope it would help.
// Store the current window handle String winHandleBefore = driver.getWindowHandle();

// Perform the click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}

// Perform the actions on new window

// Close the new window, if that window no more required
driver.close();

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

// Continue with original browser (first window)

I cannot use Switch to Window URL or Window title because URL depends on the object the user tries to open, and the title doesn’t change with the newly opened window. I can use “Switch to Window Index” for now, but it is really as a workaround because then I have to track how many windows (as a separate new windows or as tabs) are opened by the application and by which order.

Shouldn’t getWebDriver always return the currently active window?

Hi there,

Katalon Studio provides “Switch to Window Index” (or Window URL / Window title) keywords to switch to your desired tab. Please try to use one of those keywords before verifying objects.

Thanks.