Selenium WebDriver 工作但速度慢(Java) [英] Selenium WebDriver works but SLOW (Java)

查看:105
本文介绍了Selenium WebDriver 工作但速度慢(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium WebDriver 截取网页截图.它运行良好.但是,从我在 Eclipse 中运行到屏幕截图显示在我的本地驱动器中的时间是 7-10 秒.大多数延迟似乎是在启动 Firefox.

I am using Selenium WebDriver to take a screenshot of webpages. It runs great. However, from the time I hit run in eclipse to the time the screenshot shows up in my local drive is 7-10 seconds. Most of the latency seems to be launching Firefox.

代码:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.cnn.com");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\test\screenshot.png"));

我怎样才能加快这个过程?有没有办法可以使用已经打开的 Firefox 浏览器来节省打开新浏览器的费用?这段代码有点重吗?

How can I speed up this process? Is there a way that I can use an already opened Firefox browser to save on opening a new one? Is this code somehow heavy?

详细信息:在 CentOS box 和 Win7 box 上都使用 eclipse 进行了尝试.myspeedtest.net 显示 22Mbps 下降和 1 Mbps 上升.

Details: Tried on CentOS box and Win7 box both using eclipse. myspeedtest.net shows 22Mbps down and 1 Mbps up.

推荐答案

您要求的(允许 WebDriver 附加到正在运行的浏览器)现在是 差不多 3 年.迄今为止,该功能仍未添加.据我所知,没有办法让 Firefox 加载速度更快.不过,您可以尝试其他一些技巧.

What you are asking for (allowing WebDriver to attach to a running browser) has been an issue now for almost 3 years. To date, this feature has still not been added. As far as I am aware, there is no way to make Firefox load any faster. You can try a few other tricks though.

fp.setPreference("webdriver.load.strategy", "unstable")

引用此页面的警告:

有一个 beta 功能可以让 firefox 不用等待整页调用 .get 或 .click 后加载.这可能会导致立即发现中断,所以请务必使用隐式或显式等待.这仅适用于 Firefox,不适用于其他浏览器.

There is beta feature to make firefox not wait for the full page to load after calling .get or .click. This may cause immediate find's to break, so please be sure to use an implicit or explicit wait too. This is only available for Firefox and not other browsers.

您也可以尝试加载配置文件看看是否这完全有帮助.

You can also try loading with a profile and see if that helps at all.

这篇关于Selenium WebDriver 工作但速度慢(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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