How can I handle multiple tabs in Selenium pytest?

How can I handle multiple tabs in Selenium pytest?

Hi Miro!

To handle multiple tabs in Selenium pytest testing, you can follow the below steps -

  1. To open a new tab, you can use the below line of code:

driver.execute_script("window.open('about:blank','secondtab');")

  1. To switch to the new tab, you can use the below line of code:
#by using tab name

driver.switch_to.window("secondtab")

or

#by using tab id
driver.switch_to.window("2")

For more info, please refer to the below GitHub repo-