How to detect when Selenium loads a browser's error page

三世轮回 提交于 2019-11-29 07:14:21

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.

serv-inc

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 import Marionette
client = 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!