Created
August 15, 2013 17:52
-
-
Save lorin/6242992 to your computer and use it in GitHub Desktop.
Illustrate try/except/else
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
def click_link(browser, linktext): | |
# We try five times in the case of stale element exceptions | |
for i in range(5): | |
try: | |
browser.find_link_by_text(linktext).first.click() | |
except StaleElementReferenceException: | |
pass | |
else: | |
return | |
# Try one last time | |
browser.find_link_by_text(linktext).first.click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment