2016-03-02 664 views
-2

请在这里找到我的代码段,我使用在Linux rhel箱:司机的HtmlUnit给我com.gargoylesoftware.htmlunit.html.HtmlPage不能转换到com.gargoylesoftware.htmlunit.InteractivePage错误

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和硒jar文件在我的项目路径中。

我尝试了谷歌搜索,但无法解决它。对此有所帮助,我哪里出错了。

在此先感谢

回答

1

这之间和的HtmlUnit webdriver的版本不兼容。

com.gargoylesoftware.htmlunit.InteractivePage于2015年7月26日引入HtmlUnit,作为HtmlPage的新基准类别corresponds to release 2.18

但是,WebDriver自版本2.48.0以来一直是checking for InteractivePage,您必须拥有它。所以任何人混合WebDriver> = 2.48与HtmlUnit < 2.18会得到该错误。

的解决方案是更新您的HtmlUnit(2.20是最新的) - 或者,如果你使用Maven等,完全消除依赖,为正确的版本应该/将通过自身的webdriver包括。

相关问题