2016-03-02 666 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包括。

相關問題