2
from selenium import webdriver

driver = webdriver.Chrome()
driver.set_page_load_timeout(7)

def urlOpen(url):
    try:
        driver.get(url)
        print(driver.current_url)
    except:
        driver.delete_all_cookies()
        print("Failed")
        return

urls = ['http://motahari.ir/', 'https://facebook.com', 'https://google.com']

for url in urls:
    urlOpen(url)

Actually, this question was Python Selenium. How to use driver.set_page_load_timeout() properly?.

The modified code above works just fine usually, but strangely, about 2 out of 10 times delete_all_cookies() throws timeoutException. I tried adding another try-catch block, implicit/explicit wait, or time.sleep before delete_all_cookies() but all didn't work.

I have no idea why and how delete_all_cookies() throws timeoutException... Is there any way to prevent that?

Traceback (most recent call last):
  File "C:/urlOpen.py", line 19, in <module>
urlOpen(url)
  File "C:/urlOpen.py", line 12, in urlOpen
driver.delete_all_cookies()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 692, in delete_all_cookies
self.execute(Command.DELETE_ALL_COOKIES)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
  (Session info: chrome=61.0.3163.100)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)

Sometimes, I get

Traceback (most recent call last):
  File "C:/urlOpen.py", line 18, in <module>
urlOpen(url)
  File "C:/urlOpen.py", line 11, in urlOpen
driver.delete_all_cookies()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 692, in delete_all_cookies
self.execute(Command.DELETE_ALL_COOKIES)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: chrome=61.0.3163.100)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)
3
  • 1
    strange issue, can u please paste the exception log Commented Oct 11, 2017 at 10:20
  • 1
    Had you find what was the cause? I am experiencing the same problem. Commented Nov 24, 2017 at 22:49
  • 1
    2 years later, I am also experiencing this. I am catching the exception and moving on, but I would like it to actually delete the cookies. Commented Jun 8, 2019 at 21:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.