Hello guys,
I would like to open a new tab in my opened browser and then read the content, I have tried with Selenium but I cannot find the way to open a new tab in the opened browser as I mentioned.
Thank you in advance
What do u want exactly? U can do it with selenium probably. Why do u need to open a new tab? U can use "get" method again ?
# Opens a new tab
driver.execute_script("window.open()")
# Switch to the newly opened tab
driver.switch_to.window(driver.window_handles[1])
# Navigate to new URL in new tab
driver.get("https://google.com")
# Run other commands in the new tab here
You're then able to close the original tab as follows
# Switch to original tab
driver.switch_to.window(driver.window_handles[0])
# Close original tab
driver.close()
# Switch back to newly opened tab, which is now in position 0
driver.switch_to.window(driver.window_handles[0])
Or close the newly opened tab
# Close current tab
driver.close()
# Switch back to original tab
driver.switch_to.window(driver.window_handles[0])