CefSharp-获取HTML元素的值 [英] CefSharp - Get Value of HTML Element

查看:1261
本文介绍了CefSharp-获取HTML元素的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CefSharp获取HTML元素的值?

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

我知道如何使用默认的WebBrowser控件:

I know how to do with this default WebBrowser Control:

Dim Elem As HtmlElement = WebBrowser1.Document.GetElementByID("id")

但是我没有找到与CefSharp类似的东西。我使用CefSharp的主要原因是网站的一部分使用iframe存储源,而默认的WebBrowser不支持它。另外,CefSharp是否可以选择调用InvokeMember或类似的呼叫?

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?

我正在使用最新版本的CefSharp。

I'm using the latest release of CefSharp by the way.

推荐答案

在他们的常见问题解答中有一个非常好的示例。

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.
        }      
    });

这篇关于CefSharp-获取HTML元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆