Welcome Guest Search | Active Topics | Sign In | Register

Cast EvalScript into Elements array Options
piess105
Posted: Monday, April 27, 2015 9:59:14 AM
Rank: Newbie
Groups: Member

Joined: 4/27/2015
Posts: 6
Hi, is there any way to cast EvalScript into Elements array, if the script actually return elements? Below there is an example:

Code: C#
EO.WebBrowser.DOM.Element [] elements = webView1.EvalScript("document.getElementsByTagName(\"input\")") as EO.WebBrowser.DOM.Element [];



Thanks in advance, your product is great!!
eo_support
Posted: Monday, April 27, 2015 10:51:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

You would cast it to a JSObject, then to a JSArray object:

Code: C#
//Cast the return value to a JSArray object
JSObject obj = (JSObject)webView1.EvalScript("....");
JSArray array = obj.ToArray();

I do not believe there is built-in support to cast it directly to a typed array. However once you have a JSArray, you can loop through it to cast each array element into a typed element:

Code: C#
//Cast a JSArray object to a DOM.Element array
DOM.Element[] elements = new DOM.Element[array.Length];
for (int i = 0; i < elements.Length; i++)
    elements[i] = array[i].CastTo<DOM.Element>();


Note that you must use JSObject.Cast method to cast the array element.

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!
piess105
Posted: Monday, April 27, 2015 12:45:52 PM
Rank: Newbie
Groups: Member

Joined: 4/27/2015
Posts: 6
thank you very much works perfectly!!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.