Selenium WebDriver工作但SLOW(Java)

前端之家收集整理的这篇文章主要介绍了Selenium WebDriver工作但SLOW(Java)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Selenium WebDriver来截取网页的截图.运行良好然而,从我在 eclipse中运行的时候到截图在本地驱动器上显示的时间是7-10秒.大多数延迟似乎是推出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浏览器来保存打开一个新的浏览器?这个代码有点重吗?

详细信息:试用CentOS盒和Win7盒都使用eclipse. myspeedtest.net显示22Mbps下降和1 Mbps上.

解决方法

您要求的(允许WebDriver附加到正在运行的浏览器)现在已经成为 almost 3 years的一个问题.迄今为止,此功能尚未添加.据我所知,没有办法使Firefox加载更快.你可以尝试一些其他的技巧.
fp.setPreference("webdriver.load.strategy","unstable")

引用this page的警告:

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.

您也可以尝试loading with a profile,看看是否有帮助.

原文链接:https://www.f2er.com/java/122297.html

猜你在找的Java相关文章