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 = WebBrowser1.Document.GetElementByID("id")
But I didn't find anything similar for CefSharp. The main reason I am using CefSharp is because part of the website is using iframes to store the source and default WebBrowser doesn't support it. Also, does CefSharp have an option to InvokeMember or similar call?
I'm using the latest release of CefSharp by the way.
this is the only way that worked for me, version 57.0.0.0..
((CefSharp.Wpf.ChromiumWebBrowser)chromeBrowser).FrameLoadEnd += Browser_FrameLoadEnd;
....
async void Browser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
Console.WriteLine("cef-"+e.Url);
if (e.Frame.IsMain)
{
string HTML = await e.Frame.GetSourceAsync();
Console.WriteLine(HTML);
}
}
This worked for me. You can modify it by yourself.
private async void TEST()
{
string script = "document.getElementsByClassName('glass')[0]['firstElementChild']['firstChild']['wholeText']";
JavascriptResponse response = await browser.EvaluateScriptAsync(script);
label1.Text = response.Result.ToString();
}
Maybe this can do your job.
private async void TEST()
{
string script = "Document.GetElementByID('id').value";
JavascriptResponse response = await browser.EvaluateScriptAsync(script);
string resultS = response.Result.ToString(); // whatever you need
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With