Recommended way to switching tabs (and closing tabs)


Hi all!
So I have a test in which I need to click on an icon. That icon will open a new tab. On the second tab I need to click on something and do a boolean to check if something exists. I can’t figure out how to safely switch to the new tab.
I have tried to send keys (control,Tab,and shift) but I can’t get the syntax quite right.
How would you recommend doing this?


Hello @micheleaz!
The best approach for switching to a new tab and performing actions on it is using the driver.getWindowHandles() and driver.switchTo().window() methods.
Basically, the first method picks up all the window handles from the currently opened tabs, which you can use in the second method to switch to your desired tab.
You can take a look at our how-to post regarding this topic for more information and examples.