簡體   English   中英

WebView2 - 獲取屬性

[英]WebView2 - Get an attribute

我正在嘗試了解 WebView2 中的體系結構。 使用 WebBrowser,我曾經從 GetElementById 返回的結果中獲取屬性,如下所示: Document.GetElementById("DropDownList").GetAttribute("selectedIndex")

我知道 WebView2 中的ExecuteScriptAsync可以運行 javascript 並將結果作為字符串返回。 但是,它看起來不知道如何從元素中獲取屬性。 以下代碼返回 null。 雖然, getElementById 返回正確的結果。
ExecuteScriptAsync("document.getElementById('DropDownList').getAttribute('selectedIndex')")

我的語法不正確嗎? 如何在 WebView2 中獲取屬性? 我們是否必須在腳本中寫一個 function 並從主機調用它?

謝謝

HTMLSelectElement沒有名為“selectedIndex”的屬性。 它有一個名為“selectedIndex”的屬性。

WebView2中這樣調用它:

await ExecuteScriptAsync("document.getElementById('DropDownList').selectedIndex");

您需要等待此方法。 見參考

string res = await ExecuteScriptAsync("document.getElementById('DropDownList').getAttribute('selectedIndex')")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM