-2

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

I am getting the below error:

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 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.

Thanks in advance

Dag Høidahl
  • 7,873
  • 8
  • 53
  • 66
Ram
  • 9
  • 2

1 Answers1

1

This is a version incompatibility between HtmlUnit and WebDriver.

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.

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.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73