I am running a simple piece of code that downloads a website through proxy, however sometimes the proxy can be slow and this can cause the WebDriver .get(url) request to block indefinitely.
Is there a simple piece of Python code for WebDriver that will set a timeout for this function? Through searching I've only found techniques that work for java.
driver.get(url)
You can easily get the current URL of a web page when performing Python automation testing — to do that, you just need to access the current_url method of the Selenium WebDriver object.
Get Current URL Command In WebDriver, this method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value.
We can keep a session alive for long Selenium scripts in automation. In Chrome browser, this can be achieved with the help of the ChromeOptions and Capabilities classes. Capabilities class can get the capabilities of the browser by using the method – getCapabilities.
For all the web cretents out there what I used to solve this problem was this. Selenium uses the socket library so I set a timeout on the socket module, this throws an error which 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With