Last active
July 27, 2017 10:34
-
-
Save wilvk/e07df4e6e12ba542b114914959af7b93 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
from selenium import webdriver | |
from pyvirtualdisplay import Display | |
import time | |
import timeit | |
def click_link_until_page_changes(browser, link_name, timeout_seconds=300): | |
start_time = timeit.default_timer() | |
current_page_id = browser.find_element_by_tag_name('html').id | |
new_page_id = current_page_id | |
link = browser.find_element_by_link_text(link_name) | |
while current_page_id == new_page_id: | |
link.click() | |
new_page_id = browser.find_element_by_tag_name('html').id | |
time.sleep(1) | |
elapsed = timeit.default_timer() - start_time | |
if elapsed >= timeout_seconds: | |
raise Exception("Timeout of " + str(timeout_seconds) + " has been exceeded.") | |
try: | |
display = Display(visible=0, size=(1024, 768)) | |
display.start() | |
print "getting website" | |
browser = webdriver.Firefox() | |
browser.get('http://google.com') | |
assert len(browser.title) > 0 | |
print "Website exists" | |
print "clicking link" | |
click_link_until_page_changes(browser, 'Gmail') | |
print "display title" | |
print browser.title | |
except Exception as e: | |
print "Error testing website: " + str(e) | |
raise | |
finally: | |
if 'driver' in vars(): | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment