Skip to content

Instantly share code, notes, and snippets.

@uluQulu
Created August 16, 2018 13:45
Show Gist options
  • Select an option

  • Save uluQulu/b5206dee85bb4f87ef554f0bd2eceec1 to your computer and use it in GitHub Desktop.

Select an option

Save uluQulu/b5206dee85bb4f87ef554f0bd2eceec1 to your computer and use it in GitHub Desktop.
fgisslen - selenium TimeoutExeption handling
def web_adress_navigator(browser, link):
"""Checks and compares current URL of web page and the URL to be navigated and if it is different, it does navigate"""
total_timeouts = 0
try:
current_url = browser.current_url
except WebDriverException:
try:
current_url = browser.execute_script("return window.location.href")
except WebDriverException:
current_url = None
if current_url is None or current_url != link:
# handle famous timeout exceptions during `GET` method
while True:
try:
browser.get(link)
break
except TimeoutException as exc:
if total_timeouts >= 7:
raise TimeoutException("Retried {} times to GET '{}' webpage "
"but failed out of a timeout!\n\t{}".format(total_timeouts,
str(link).encode("utf-8"), str(exc).encode("utf-8")))
total_timeouts += 1
sleep(2)
# update server calls
update_activity()
sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment