0

I'm trying to build a single-page application in C#. The frame will contain a container that holds a website viewer and, beneath it, a single button.

When opening the application, the page will be shown to the user. When the user clicks the button, it's supposed to search inside the website for a specific HTML element with a class name.

The main problem is that I cannot get the website's HTML to be the same as what is shown in inspect mode in the browser. The HTML I get from the WebView2 object contains only the parent elements and inside them, the scripts that the web is running in the background to load the data. In inspect mode, the browser shows the entire HTML tree, and that's what I would like to achieve.

This is the code I'm using to get the HTML of the webpage:

var script = "document.documentElement.outerHTML";
var result = await webView.CoreWebView2.ExecuteScriptAsync(script);

Thanks in advance.

var script = "document.documentElement.innerHTML";
var result = await webView.CoreWebView2.ExecuteScriptAsync(script);
  • You have to wait until the page is fully loaded including the dynamic content. Please check out the following answer: https://stackoverflow.com/a/66053672/7128891 – qwermike Aug 03 '23 at 11:23

0 Answers0