Created
November 29, 2012 04:02
-
-
Save douglasmiranda/4166748 to your computer and use it in GitHub Desktop.
working with pop-up (adapted)
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
from splinter.browser import Browser | |
browser = Browser() | |
browser.visit('http://media.douglasmiranda.com/labs/exemplos/splinter_pop-up/') | |
parent_window = browser.current_window # Save the parent window | |
browser.find_by_id('open-popup').first.click() | |
for window in browser.windows: | |
# Switch to a different window (the pop-up) | |
browser.switch_to_window(window) | |
# Check if this is the one we want by comparing the title | |
if browser.title == 'Pop-up Window': | |
break | |
# Most of the times there are only two windows | |
# the parent and the pop-up. | |
# In this case the following condition also does the trick | |
# if window != browser.parent_window: | |
# break | |
# now 'browser' is the pop-up instance | |
# Proves we can interact with the popup | |
if browser.is_element_present_by_id('pop-up-content-div-element'): | |
print browser.find_by_id('pop-up-content-div-element').text | |
browser.find_by_id("close-popup").first.click() | |
# let's switch back to the parent_window | |
# now 'browser' is, again, the main window, so you can manipulate as always | |
browser.switch_to_window(parent_window) | |
print browser.find_by_css('h1').first.text | |
browser.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment