I am trying to understand the architecture in WebView2. With WebBrowser i used to get an attribute from a result returned by the GetElementById as follows: Document.GetElementById("DropDownList").GetAttribute("selectedIndex")
I know that the ExecuteScriptAsync
in WebView2 can run a javascript and return a result as a string. However, it looks like that it does not know how to get an attribute from an element. The below code returns a null. Although, the getElementById returns the correct result.
ExecuteScriptAsync("document.getElementById('DropDownList').getAttribute('selectedIndex')")
Is my syntax incorrect? How to get an attribute in WebView2?. Do we have to write a function in the script and call it from the host?
Thanks