How do I get an element collection from EvaluateScriptAsync?

732 views
Skip to first unread message

ehel...@gmail.com

unread,
Apr 11, 2018, 11:22:16 AM4/11/18
to CefSharp

The web page I load with the CefSharp Browser has 2 elements with ClassName "abc". 

The innerText of abc[0] is "This".  The innerText of abc[1] is "That".

Example 1

When I execute (after !args.IsLoading is true)

var z = await browser.EvaluateScriptAsync("document.getElementsByClassName('abc')[1].innerText")

"success" is true and "result" is "That".

Example 2

But when I execute

var z = await browser.EvaluateScriptAsync("document.getElementsByClassName('abc').innerText"), "success" is true but "result" is null.

Is the FAQ answer "Only trivial values can be returned (like int, bool, string etc) - not a complex (user-defined) type which you have defined yourself. This is because there is no (easy) way to expose a random JavaScript object to the .NET world, at least not today." the reason why?


I've tried HtmlElementCollection coll = await browser.EvaluateScriptAsync ("document.getElementsByClassName('ABC').innerText")


but that won't compile, giving me the error 'Cannot implicitly convert type 'CefSharpJavascriptResponse' to 'System.Windows.Forms.HtmlElementCollection'.


Is there any way I can change my code to get both 'abc' elements in example 2?

 

Reply all
Reply to author
Forward
0 new messages