Aug-03-2020, 01:52 AM
# 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])
Recommended Tutorials: