我试图理解 WebView2 中的架构。使用 WebBrowser,我曾经从 GetElementById 返回的结果中获取属性,如下所示:Document.GetElementById("DropDownList").GetAttribute("selectedIndex")
我知道ExecuteScriptAsync
WebView2 中的 可以运行 JavaScript 并以字符串形式返回结果。但是,它看起来不知道如何从元素获取属性。下面的代码返回一个空值。尽管如此, getElementById 返回正确的结果。
ExecuteScriptAsync("document.getElementById('DropDownList').getAttribute('selectedIndex')")
我的语法不正确吗?如何获取WebView2中的属性?我们是否必须在脚本中编写一个函数并从主机调用它?
谢谢