如何从 GetElementById 获取值?

How to get value from GetElementById?

nxuybcbkbcbggkcwcbregrwyywbrgewb​​yrewyreyrwebyrwrwe 测试

Browser.ExecuteScriptAsync();

发送 javascript 并在 return 中不期望任何内容,因此尝试将 'nothing'(即无效)分配给 HtmlElement 变量是不行的。

如果您希望发送 javascript 的页面并使用返回的内容,则需要使用 EvaluateScriptAsync()

这将 return 一个 Task<JavascriptResponse>,如果您试图将它分配给 Size,它仍然无法工作。坏消息是:JavascriptResponse 只能是基本数据类型(int、bool、string 等)。根据他们的文档:

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)

有关详细信息,请参阅: https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions