¿Cómo detectar fallas en la red mientras se invoca el método get () a través de Selenium y Python?
Estoy usando Chrome con selenio y la prueba se ejecutó bien, hasta que de repente la conexión a Internet / proxy no funciona, luego browser.get (url) me da esto:
Si vuelvo a cargar la página 99%, se cargará bien, ¿cuál es la forma correcta de manejar esto?
MI 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')
No me estoy metiendo en TIMEOUT EXCEPTION sino en la parte de descanso.