gpt4 book ai didi

java - 如何使用java处理phantomjs selenium中的javascript错误?

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:51 24 4
gpt4 key购买 nike

我尝试了很多,但没有得到任何解决方案如何处理 page.onError ,代码如下 -

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setJavascriptEnabled(true);
desiredCapabilities.setCapability("takesScreenshot", false);
WebDriver driver = new PhantomJSDriver(desiredCapabilities);

我收到以下错误 -

[ERROR - 2017-08-09T06:00:16.732Z] Session [db2e4bf0-7cc7-11e7-a9b1-81e10abf02db] - page.onError - msg: TypeError: null is not an object (evaluating 'document.getElementById("img").src=images[x]')

phantomjs://platform/console++.js:263 in error [ERROR - 2017-08-09T06:00:16.733Z] Session [db2e4bf0-7cc7-11e7-a9b1-81e10abf02db] - page.onError - stack:

最佳答案

要将 Selenium 3.4.0PhantomJS 2.1.1 配合使用,您需要通过 System.setProperty 命令提供 PhantomJS 二进制文件绝对路径,如下所示:

File src = new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setJavascriptEnabled(true);
desiredCapabilities.setCapability("takesScreenshot", false);
WebDriver driver = new PhantomJSDriver();
driver.get("https://www.facebook.com/");
System.out.println("Facebook Page Loaded");

关于java - 如何使用java处理phantomjs selenium中的javascript错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45582828/

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