【问题标题】:htmlunit driver gives me com.gargoylesoftware.htmlunit.html.HtmlPage cannot be cast to com.gargoylesoftware.htmlunit.InteractivePage errorhtmlunit 驱动程序给了我 com.gargoylesoftware.htmlunit.html.HtmlPage cannot be cast to com.gargoylesoftware.htmlunit.InteractivePage 错误
【发布时间】:2016-03-02 05:46:11
【问题描述】:

请在此处找到我的代码 sn-p,我在 linux 中使用 rhel 框:

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

我尝试了谷歌搜索,但无法解决它。可以在这方面和我出错的地方提供一些帮助。

提前致谢

【问题讨论】:

    标签: java selenium-webdriver


    【解决方案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

    解决方案是更新您的 HtmlUnit(2.20 是最新的) - 或者如果您使用 Maven 等,请完全删除依赖项,因为正确的版本应该/将由 WebDriver 本身包含。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2018-09-29
      • 1970-01-01
      相关资源
      最近更新 更多