I need to get an empty array declared in a JavaScript script in a Java variable.
The JavaScript array is declared as so on a web page:
tc_vars["products"] = new Array();
(I only need the products
's array, not the tc_vars
one).
This is how I try to get this variable in Java :
Object[] value = (Object[]) js.executeScript("return tc_vars['products'];");
(Where js
is a JavascriptExecutor
associated with a Selenium WebDriver
).
I usually have no trouble using this method for getting Strings, but it seems it just won't work for an empty Array. Moreover, I don't have any error message, the WebDriver just crashes.
The executeScript
method returns an Object
variable. Casting it to a String
(when the JS variable is a String) works well, but I had no chance in casting this empty Array to String[]
or Object[]
.