gpt4 book ai didi

Selenium WebDriver 工作但很慢(Java)

转载 作者:行者123 更新时间:2023-12-04 01:47:19 25 4
gpt4 key购买 nike

我正在使用 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 box 和 Win7 box 上都使用 eclipse 进行了尝试。 myspeedtest.net 显示下降 22 Mbps 和上升 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看看这是否有帮助。

关于Selenium WebDriver 工作但很慢(Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13020841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com