Skip to content Skip to sidebar Skip to footer

How To Detect When Selenium Loads A Browser's Error Page

Is there a universal way to detect when a selenium browser opens an error page? For example, disable your internet connection and do driver.get('http://google.com') In Firefox, Se

Solution 1:

WebDriver API doesnot expose HTTP status codes , so if you want to detect/manage HTTP errors, you should use a debugging proxy.

See Jim's excellent post Implementing WebDriver HTTP Status on how to do exactly that.

Solution 2:

If you just need to remote-control the Tor Browser, you might also consider the Marionette framework by Mozilla. Bonus: It fails when a page cannot be loaded: (see navigate(url) in the API)

The command will return with a failure if there is an error loading the document or the URL is blocked. This can occur if it fails to reach the host, the URL is malformed, the page is restricted (about:* pages), or if there is a certificate issue to name some examples.

Example use (copy from other answer):

To use with the Tor Browser, enable marionette at startup via

Browser/firefox -marionette

(inside the bundle). Then, you can connect via

from marionette importMarionetteclient= Marionette('localhost', port=2828);
client.start_session()

and load a new page for example via

url='http://mozilla.org'
client.navigate(url);

For more examples, there is a tutorial.

Post a Comment for "How To Detect When Selenium Loads A Browser's Error Page"