将 webBrowser 更改为 webView2 c#
我必须将程序中的WebBrowser控件升级到WebView2,因为许多页面不再起作用。 我有一种返回激活元素的内部文本的方法,
if (XtraMessageBox.Show(this, "Text:\r\n\r\n" +
webBrowser.Document.ActiveElement.InnerText + "\r\n\r\n" +
"will be added to description",
"DESCRIPTION UPDATE", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
.Equals(DialogResult.No))
return;
descriptionMemoEdit.EditValue += webBrowser.Document.ActiveElement.InnerText;
我试图找到相当于WebView2的方法,但我找不到任何东西。 我尝试了
webView.ExecuteScriptAsync("document.ActiveElement.InnerText").ToString()
and
webView.CoreWebView2.ExecuteScriptAsync("document.ActiveElement.InnerText").ToString()
,但它只是返回 system.threading.tasks.task`1 [System.String],而不是实际文本。 我看到WebView2没有DOM。 我该如何获得Innertext?
I must upgrade webBrowser control in my program to webView2 because many pages are not working anymore.
I have a method that returns the inner text of the activelement
if (XtraMessageBox.Show(this, "Text:\r\n\r\n" +
webBrowser.Document.ActiveElement.InnerText + "\r\n\r\n" +
"will be added to description",
"DESCRIPTION UPDATE", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
.Equals(DialogResult.No))
return;
descriptionMemoEdit.EditValue += webBrowser.Document.ActiveElement.InnerText;
I am trying to find an equivalent to webView2 but I cant find anything.
I tried
webView.ExecuteScriptAsync("document.ActiveElement.InnerText").ToString()
and
webView.CoreWebView2.ExecuteScriptAsync("document.ActiveElement.InnerText").ToString()
but it just returns
System.Threading.Tasks.Task`1[System.String] and not the actual text.
I saw that webView2 doesnt have DOM.
How can I get the innertext?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以像这样使用它。
别忘了等待。
编辑:
将 webView21_CoreWebView2InitializationCompleted 事件添加到您的 webview2。
在您的活动中添加此示例代码。
然后添加一些方法。
You can use it like this.
Don't forget to put await.
EDITED :
Add a webView21_CoreWebView2InitializationCompleted event to your webview2.
On your event add this sample code.
Then add some method.