硒确定浏览器被冻结 [英] Selenium determine browser is frozen

查看:104
本文介绍了硒确定浏览器被冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用selenium做一些涉及加载大量页面的工作,其中可能包含大量图像和/或Flash广告,由于我的firefox浏览器处于冻结状态,因此在浏览器上的压力似乎相当大。
硒是否能够检测浏览器是否被冻结,如在任务管理器中达到了不响应的可怕状态,并且如果我单击选项卡就不会关注?
如果没有,是否有人知道如何处理这种情况?

I'm using selenium to do some stuff that involves loading quite a number of pages, potentially with numerous images and/or flash ads, which is apparently rather stressful on the browsers, since my firefox browsers are freezing. Is selenium capable of detecting if a browser is frozen, as in has reached that horrid state of "not responding" in the task manager and won't focus if i click on the tab? If not, does anybody know of a way to deal with that case?

编辑:

我最终使用以下命令:

  browser = webdriver.Firefox()
  try:
    browser.set_page_load_timeout(_DEFAULT_LOAD_TIME)
    browser.get('http://' + domain)
  except TimeoutException as te:
    print "Loading %s timed out. Killing browser." % domain
    print te
    browser.close()

尽管没有如果浏览器进入(不响应)状态,但是关闭浏览器,但是_DEFAULT_LOAD_TIME足够低,通常可以在进入该状态之前杀死浏览器。

Although it does not close the browser if it gets into a (not responding) state, but with a low enough _DEFAULT_LOAD_TIME, it usually manages to kill the browser before it gets into that state.

推荐答案

至少您可以为Selenium设置超时。在以下示例中,网络驱动程序将最多等待10秒,然后终止浏览器并通过测试。这样,您就可以最终执行所有测试。

At least you can set a timeout for Selenium. In the following example the webdriver will wait at most 10 seconds before killing the browser and failing the test. This way you can get all the tests executed eventually.

from selenium import webdriver

ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds
ff.get("http://somedomain/url_that_delays_loading")
myDynamicElement = ff.find_element_by_id("myDynamicElement")

有关详细信息,请参见硒总部

See more information at Selenium headquarters

这篇关于硒确定浏览器被冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆