Python Selenium WebDriver how to add timeout to get (url) function

I am running a simple piece of code that loads a website through a proxy server, however sometimes the proxy server can be slow, and this can cause the WebDriver.get (url) request to be blocked indefinitely.

Is there any simple Python code for WebDriver that will set a timeout for this function? Through a search, I found methods that work for java.

driver.get(url) 
+8
python selenium timeout webdriver driver
source share
2 answers

For all the websites that I used to solve this problem, it was. Selenium uses the socket library, so I set a timeout in the socket module, this causes an error that we can use to send the escape key to the browser (which stops the page loading):

 socket.setdefaulttimeout(2) try: driver.get(pageLink) except socket.timeout: #send ESCAPE key to browser 
+7
source share

Found this in docs

selenium.webdriver.remote.webdriver.set_script_timeout (TIME_TO_WAIT)

 Set the amount of time that the script should wait before throwing an error. time_to_wait: The amount of time to wait Usage: driver.set_script_timeout(30) 
+4
source share

All Articles