htmlunit驱动程序给我com.gargoylesoftware.htmlunit.html.HtmlPage无法转换为com.gargoylesoftware.htmlunit.InteractivePage错误
请在此处找到我的代码段,并且我在linux中使用rhel
框:
Please find my code snippet here and I am using rhel
box in linux:
WebDriver driver = new HtmlUnitDriver();
driver.get("https://www.amazon.com/ap/register?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dnav_newcust");
driver.findElement(By.id("ap_customer_name")).sendKeys("krish"); // line 24
我收到以下错误:
Exception in thread "main" java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlPage cannot be cast to com.gargoylesoftware.htmlunit.InteractivePage
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitTargetLocator.activeElement(HtmlUnitDriver.java:1332)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.switchFocusToThisIfNeeded(HtmlUnitWebElement.java:292)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.sendKeys(HtmlUnitWebElement.java:330)
at com.amazon.digitalmusic.UnitBrowser.main(UnitBrowser.java:24)
HTMLunit-2.17和Selenium jar文件在我的项目路径中.
HTMLunit-2.17 and selenium jar files are there in my project path.
我尝试了谷歌搜索,但无法解决.在这方面以及我出了问题的地方可以提供一些帮助.
I tried googling but could not be able to resolve it. Could some help in this and where I went wrong.
预先感谢
这是HtmlUnit和WebDriver之间的版本不兼容.
This is a version incompatibility between HtmlUnit and WebDriver.
com.gargoylesoftware.htmlunit.InteractivePage
作为HtmlPage
的新基类于2015年7月26日引入HtmlUnit,它是
com.gargoylesoftware.htmlunit.InteractivePage
was introduced into HtmlUnit on 26 July 2015, as the new base class for HtmlPage
, which corresponds to release 2.18.
However, WebDriver has been checking for InteractivePage
since release 2.48.0, which you must have. So anyone mixing up WebDriver >= 2.48 with HtmlUnit < 2.18 is going to get that error.
解决方案是更新HtmlUnit(最新版本为 2.20 ),或者,如果您使用Maven等,请完全删除依赖项,因为WebDriver本身应该/将包含正确的版本.
The solution is to update your HtmlUnit (2.20 is the latest) - or if you use Maven etc., remove the dependency altogether, as the correct version should/will be included by WebDriver itself.