0

I have A Selenium WebDriver script in Python that I need to run for a long time to complete in a headless browser mode. The thing is that after a while I get the exception

disconnected: Unable to receive message from renderer
  (failed to check if window was closed: disconnected: not connected to DevTools)

From what I have read, this occurs when no interaction with the page is done for a while, for longer than the time set as Script timeout (I have set a value of 36000). To try to prevent this from happening, I am trying to refresh the page when this happens and continue with the next iteration if the error occurs, but it does not seem to work.

 while current_iteration < num_iterations:
                current_iteration += 1
                print(f"    * ITERATION {current_iteration} ")
                try:
                    # Function I use to take certain actions in the iterative process (this works until iteration 761 aprox., where the webdriver disconnects)
                    takeAction()
                except  WebDriverException as e:
                    print("WebDriverException occurred:", str(e))
                    # Handle the exception by refreshing the page or restarting the browser
                    driver.refresh()

                except Exception as e:
                    print(f"WARNING: An uncaught exception occurred during the current iteration")
                    print(e)
                    driver.refresh()

I have seen on other posts, if I have understood it correctly, that this may happen if the loaded URL leads to a page with too many content, but this does not seem to be the case, as the loaded page has previously been loaded in the same conditions on previous steps of the process without any problem.

I would like to know the reason why the webdriver disconnects if I am constantly interacting with the page. Also, I'd like to know how to handle this situation for my script to be able to continue even if the script has been running for a long time, as refreshing the page does not seem to be working.

0 Answers0