c#win表单中webview中Document.GetElementFromPoint(e.ClientMousePosition)的替代方法

c#win表单中webview中Document.GetElementFromPoint(e.ClientMousePosition)的替代方法,c#,winforms,webview,C#,Winforms,Webview,我正在使用 HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition); 从web浏览器控件中的点获取元素。我想在web视图中通过鼠标单击获取html元素。在web视图控件中,除此之外的任何选项都可以按照此处的说明进行操作: 与web视图内容交互 您可以使用 InvokeScriptAsync方法调用脚本或将脚本注入web视图 内容和ScriptNotify事件,以从 web视图内容 所

我正在使用

HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);

从web浏览器控件中的点获取元素。我想在web视图中通过鼠标单击获取html元素。在web视图控件中,除此之外的任何选项都可以按照此处的说明进行操作:

与web视图内容交互

您可以使用 InvokeScriptAsync方法调用脚本或将脚本注入web视图 内容和ScriptNotify事件,以从 web视图内容

所以你可以这样做:

    private void WebView1_DOMContentLoaded(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlDOMContentLoadedEventArgs e)
        {
            String func = @" document.addEventListener('click', function(e){
                             //Get the Div Tag Name and its ID as string back into our code
                             window.external.notify(e.target.tagName + '(' + e.target.id + ')');
                            });";
            webView1.InvokeScriptAsync("eval", func);
        }

        private void WebView1_ScriptNotify(object sender, Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlScriptNotifyEventArgs e)
        {
            string s = e.Value; //This will give you the Div Tag Name and ID
        }