Last active
September 1, 2018 16:49
-
-
Save uluQulu/83a4eb51a84e08bcf9013c2cce5431f1 to your computer and use it in GitHub Desktop.
Open a new tab; Do stuff in it; Close it
This file contains hidden or 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
@contextmanager | |
def new_tab(browser): | |
""" USE once a host tab must remain untouched and yet needs extra data- get from guest tab """ | |
try: | |
# add a guest tab | |
browser.execute_script("window.open()") | |
# switch to the guest tab | |
browser.switch_to.window(browser.window_handles[1]) | |
yield | |
finally: | |
# close the guest tab | |
browser.execute_script("window.close()") | |
# return to the host tab | |
browser.switch_to.window(browser.window_handles[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment