How to get value from GetElementById?

495 views Asked by At

nxuybcbkbcbggkcwcbregrwyywbrgewbyrewyreyrwebyrwrwe test

1

There are 1 answers

1
Pat On BEST ANSWER
Browser.ExecuteScriptAsync();

Sends javascript to be executed and expects nothing in return, so trying to assign 'nothing' (ie void) to an HtmlElement variable is a no go.

If you are looking to send the page a bit of javascript, and use what is sent back, you need to use EvaluateScriptAsync()

This will return a Task<JavascriptResponse> which will still not work if you are trying to assign it to Size. Here is the bad news: JavascriptResponse can only be basic data types (int, bool, string, etc.). As per their documentation:

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. However, one possible technique is to turn the Javascript object you wish to return to your .NET code into a JSON string with the Javascript JSON.toStringify() method and return that string to your .NET code. Then you can decode that string into a .NET object with something like JSON.net. See this MSDN link for more information. (https://msdn.microsoft.com/en-us/library/ie/cc836459(v=vs.94).aspx)

For more info see: https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions