0

I am using HtmlUnit to get a page from server. the page has lots of javascript and i want to get some variable values (array, json etc) from page. Is there a way to get all the global variables? the code i am using to get variable is as below

ScriptResult scr = result.executeJavaScript("User");
scr.getJavaScriptResult();

when i print this variable it shows [object Object] how do i get properties of this variable. I know that there is a property "id" so i can simply call result.executeJavaScript("User.id") but there are some more which i don't know at this time. how i can see all the properties? same problem is with the Json object

var Item = {Locations: {"1":{"name":"New York", "desc":"xyz"}}

the same issue is here

result.executeJavaScript("Item.Locations");

return [object Object], Is there any way to get whole json object at once?

vermap
  • 211
  • 1
  • 2
  • 10

1 Answers1

0

Okay so i find that [object object] is nothing but an instance of NativeObject so simply cast it and traverse using iterator Iterator<Entry<Object,Object>> entryset = ((NativeObject)scr.getJavaScriptResult()).entrySet().iterator();

vermap
  • 211
  • 1
  • 2
  • 10