Como detectar falhas de rede ao invocar o método get () através do Selenium e Python?
Estou usando o Chrome com selênio e o teste é bom, até que de repente a conexão à Internet / proxy esteja inoperante e, em seguida, browser.get (url) me faça o seguinte:
Se eu recarregar a página 99%, ela carregará bem, qual é a maneira correta de lidar com isso?
MEU CÓDIGO:
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')
Não estou entrando no TIMEOUT EXCEPTION, mas na parte do intervalo.