1

I may be missing something simple here but I have tried a lot already without any luck. I'm new to selenium and I cannot correct the following issue. When navigating to a web-page using get() I continually get a timeout message. The page loads properly but after everything on the page loads (i assume it may have something to do with how long it takes to load due to the ads loading) I get this error.

selenium.common.exceptions.TimeoutException: Message: timeout (Session info: chrome=65.0.3325.181) (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)

I have tried the following; moving chromedriver location, trying older versions of selenium, waits, implicitly waits, time.sleep and others. Any input would be great as this seems like something simple and I would like to get it fixed soon.

The code in question:

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("Path\To\chromedriver.exe")
driver.set_page_load_timeout(10)

driver.get("https://www.website.com")
driver.find_element_by_name("name").send_keys("com")
driver.find_element_by_name("word").send_keys("pw")
driver.find_element_by_id("idItem").click()

driver.find_element_by_name("word").send_keys(Keys.ENTER)

#driver.implicitly_wait(10)
driver.get("https://www.website2.com")
--------------Error here, never gets past this point------------
time.sleep(10)
driver.close()
chaosCoder
  • 13
  • 1
  • 3
  • 3
    you have `driver.set_page_load_timeout(10)` in your code... you understand what this does, right? – crookedleaf Apr 03 '18 at 22:38
  • It was not explained it a tutorial I watched so I thought nothing of it. DebanjanB answer corrected my misunderstanding. – chaosCoder Apr 04 '18 at 20:24
  • lol it's all good. i wasn't asking out or sarcasm or anything, i just thought you put it in yourself knowing what it did, and if so i was going to explain the Ajax issues like DebanjanB did in his answer. glad you got it figured out, though! – crookedleaf Apr 04 '18 at 23:04

1 Answers1

3

As per your question while navigating to a web-page using get() apparently it may appear that the page got loaded properly but factually the JavaScripts and Ajax Calls under the hood might not have completed and the Web Client may not have achieved 'document.readyState' is equal to "complete" as well.

But it seems you have induced set_page_load_timeout(10) in your code which incase the complete page loading (including the JS and Ajax) doesn't gets completed within 10 seconds will result in a TimeoutException. That is exactly happening in your case.

Solution

  • If your usecase doesn't have a constraint on Page Load Timeout, remove the line of code set_page_load_timeout(10)
  • If your usecase have a dependency on Page Load Timeout, catch the exception and invoke quit() to shutdown gracefully as follows :

  • Code Block :

     from selenium import webdriver
    
     driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
     driver.set_page_load_timeout(2)
     try :
         driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl")
         print("URL successfully Accessed")
         driver.quit()
     except :
         print("Page load Timeout Occured. Quiting !!!")
        driver.quit()
    
  • Console Output :

    Page load Timeout Occured. Quiting !!!
    

You can find a detailed discussion on set_page_load_timeout() in How to set the timeout of 'driver.get' for python selenium 3.8.0?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    We that was it, I knew it was something I was overlooking. The tutorial I watched added that line but they never explained why. So thank you for explain and showing an example. That corrected the issue. Thanks again DebanjanB – chaosCoder Apr 04 '18 at 20:26