Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

HTMLUnit doesn't handle Object array's in javascript properly #1280

@lukeis

Description

@lukeis

Originally reported on Google Code with ID 1280

What steps will reproduce the problem?
1. Start a HtmlUnit driver that has Firefox capabilities.
2. navigate to a page that has jquery on the page.
3. get a List of web elements by running a findElements selector.
4. execute a jQuery.makeArray function passing in the list of elements

What is the expected output? What do you see instead?
The expected output would be to get the list of WebElements back as an array.

Instead HtmlUnit throws an error:

RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object [Ljava.lang.Object;@464e32c8 of class [Ljava.lang.Object;
where it expected String, Number, Boolean or Scriptable instance. Please check your
code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object [Ljava.lang.Object;@464e32c8 of class [Ljava.lang.Object;
where it expected String, Number, Boolean or Scriptable instance. Please check your
code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object [Ljava.lang.Object;@464e32c8 of class [Ljava.lang.Object;
where it expected String, Number, Boolean or Scriptable instance. Please check your
code for missing Context.javaToJS() call.

com.gargoylesoftware.htmlunit.ScriptException: Invalid JavaScript value of type [Ljava.lang.Object;
(https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js#16)
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: Invalid JavaScript value of type [Ljava.lang.Object;
(https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js#16)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:531)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:906)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:392)

... (snip) ...

Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Invalid JavaScript
value of type [Ljava.lang.Object; (https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js#16)

... (snip) ...

== CALLING JAVASCRIPT ==

  function () {
      return $.makeArray(arguments[0]);
  }

======= EXCEPTION END ========


What version of the product are you using? On what operating system?
2.0b1, on OSX 10.6.6

Please provide any additional information below.

The WebDriver code ro reproduce the issue:

List<WebElement> els = driver.findElements(By.tagName("div"));
Object[] args = new Object[] { els };
((JavascriptExecutor)driver).executeScript("return $.makeArray(arguments[0]);", args);

The html page:

<html>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
    </head>
    <body>

        <div id="id1">Simple ID test</div>
        <div class="class1">Simple class test</div>

        <div id="block1">
            <ul>
                <li>a</li>
                <li>b</li>
                <li>c</li>
            </ul>
        </div>
   </body>
</html>

Reported by jaie.wilson on 2011-02-08 00:20:48

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions