[英]How to handle javascript error in phantomjs selenium with java?
I have tried a lot but I didn't get any solution how can I handle page.onError , code is as follow - 我已经尝试了很多,但没有得到任何解决方案,如何处理page.onError,代码如下-
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setJavascriptEnabled(true);
desiredCapabilities.setCapability("takesScreenshot", false);
WebDriver driver = new PhantomJSDriver(desiredCapabilities);
I am getting following error - 我收到以下错误-
[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]')
[错误-2017-08-09T06:00:16.732Z]会话[db2e4bf0-7cc7-11e7-a9b1-81e10abf02db]-page.onError-msg:TypeError:null不是对象(正在评估'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:
phantomjs://platform/console++.js:263错误[ERROR-2017-08-09T06:00:16.733Z]会话[db2e4bf0-7cc7-11e7-a9b1-81e10abf02db]-page.onError-堆栈:
To work with Selenium 3.4.0
with PhantomJS 2.1.1
you need to provide the absolute path of PhantomJS binary
through System.setProperty
command as follows: 要将
Selenium 3.4.0
与PhantomJS 2.1.1
一起PhantomJS 2.1.1
您需要通过System.setProperty
命令提供PhantomJS binary
的绝对路径 ,如下所示:
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.