CefSharp - Get Value of HTML Element

后端 未结 5 1322
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 10:20

How can I get the value of an HTML element with CefSharp?

I know how to do with this default WebBrowser Control:

Dim Elem As HtmlElement = WebBrowser         


        
5条回答
  •  天命终不由人
    2021-01-12 10:42

    There is a really good example of how to do this in their FAQ.

    https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#2-how-do-you-call-a-javascript-method-that-return-a-result

    Here is the code for the lazy. Pretty self explanatory and it worked well for me.

    string script = string.Format("document.getElementById('startMonth').value;");
    browser.EvaluateScriptAsync(script).ContinueWith(x =>
            {
                var response = x.Result;
    
                if (response.Success && response.Result != null)
                {
                var startDate = response.Result;
                //startDate is the value of a HTML element.
            }      
        });
    

提交回复
热议问题