I am using Chrome with selenium and the test run well, until suddenly internet/proxy connection is down, then browser.get(url) get me this:
If I reload the page 99% it will load fine, what is the proper way to handle this ?
MY CODE:
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"""
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:
retries = 5
while retries > 0:
try:
browser.get(link)
break
except TimeoutException:
logger.warning('TimeoutException when tring to reach page')
retries -= 1
while not is_connected():
sleep(60)
logger.warning('there is no valid connection')
I am not getting into TIMEOUT EXCEPTION but to the break part.
As per your question and your code trials as you are trying to access the url passed through the argument
link
you can adapt a strategy where:range()
.get(link)
your program will invokeWebDriverWait()
for a predefined interval for the url to contain a pre-definedpartialURL
from the url.try{}
block with ExpectedCondition methodtitleContains()
and in case ofTimeoutException
invokebrowser.get(link)
again within thecatch{}
block.Your modified code block will be: