It is done with CoreWebView2.ExecuteScriptAsync
You can find samples like at Chromium WebView2 Control and .NET to JavaScript Interop - Part 2 (C# but same thing in VB)
Equivalent of WebBrowser.Document in WebView2
We have a VSTO addin for MS Project 2010/2013/2016/2019, where it imports/exports data from an external application and these pages are rendered in embedded Internet Explorer browser from MS Project.
Since IE support will be ending in few years, we are moving to new embedded browser control known as the Microsoft Edge WebView2 control.
I need the handle to html document so that I can get elements from html based on element id or tag name and call click handler on html element.
Need equivalent of :
HtmlDocument doc = browser.Document
HtmlElementCollection elCol = doc.GetElementsByTagName("button");
Any help would be highly appreciated.
Thanks,
Priyanka
2 answers
Sort by: Most helpful
-
Castorix31 84,546 Reputation points
2022-03-29T18:22:10.773+00:00 -
Priyanka Songra 6 Reputation points
2022-04-12T18:24:57.88+00:00 Hi @Castorix31 ,
I tried using
String html =await webView2Browser.CoreWebView2.ExecuteScriptAsync("document.getElementById('ATTRIBUTE_PAGE_ID').value");
And then I want to compare this html to some string and perform some action, but my application is crashing after the above statement is executed.
Also do we need to initialize 'document'?
Any pointers to resolve this issue.Thanks,
Priyanka