Is there a way to let selenium ignore the timeoutexception Error and continue if it happens?

Viewed 464

I am using selenium with python and my chromedriver and chrome.exe is ver90.0

I am having a problem that the script will stop once a timeout error occurs and the problem is that it always happens, sometimes in a few hours, sometimes in a few minutes.

It will show up something like :

selenium.common.exceptions.timeoutexception: message: timeout: timed out receiving message from renderer: -0.014

when this happens, I see the webpage is usually loading and it basically can't load resulting the error occuring.

Is there a way to ignore this error and basically let the script either refresh or just continue loading to the next webpage in the list. An example code will be like this:

while True:
     driver.get(thislist[i])
     if .......:
        i = i + 1

I tried many fixes, but none of them work. I tried with beta chrome.exe and chrome webdriver ver 91.0. I also tried including chrome_options and I also tried some headers that's not in this code, but I always eneded up receiving the timeout error. I asked this question a few times before, but there hasn't bveen a fix that works.

chrome_options.add_argument('--enable-automation')
chrome_options.add_argument('--lang=en')

chrome_options.add_argument("window-size=1920,1080")
chrome_options.headless = True


chrome_options.add_experimental_option ("debuggerAddress", "localhost:8989")
driver = webdriver.Chrome(executable_path='C:/Webdriver/chromedriver', chrome_options=chrome_options)
   
     
2 Answers

What about adding a try catch around your operation that raises the error. If there is an error, you simply continue in your loop.

Use Exception since your don't know the kind of exception that will be thrown.


You can always set the timeout for selenium to be longer with the following line: driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

while True:
    try:
        driver.get(thislist[i])
    except timeoutexception as e:
        print(e)
        continue
    else:
        # do what you want here

When there is a timeoutexception, the code will just print it and continue to the next loop. If there is no one, then you can do web driving under "else:".

Thanks for reading.

Related