Last active
December 15, 2016 01:14
-
-
Save amagee/d49037153e0b87eaf295cbdaefbb77ef to your computer and use it in GitHub Desktop.
Selenium switch tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Current versions of Selenium are so silly that if an action on the page | |
# results in a new tab being opened, the browser will switch to the new tab, | |
# but the selenium driver will still think the old tab is visible, so if you | |
# try to access elements on the old tab, they will fail with 'element not visible' | |
# errors. | |
# One way to fix this is to explicitly switch to the new tab and close it | |
# (if you have an element that will close the tab). | |
driver.switch_to.window(driver.window_handles[1]) | |
driver.find_element_by_css_selector(".my-close-button").click() | |
driver.switch_to.window(driver.window_handles[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment