Results 1 to 6 of 6

Thread: [RESOLVED]Why can't I programatically fetch HTML from Webview2 (need to click button)

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2022
    Posts
    83

    Resolved [RESOLVED]Why can't I programatically fetch HTML from Webview2 (need to click button)

    I can successfully fetch the inner text from google.com/index.html using the code below, but must click on a button. However, I would rather invoke an Await somehow to set the value of the sHTML string immediately after initbrowser(). However, I have tried using an Async Function "name" As Task, and awaited for sHTML to be set, but the CoreWebView2 is nothing (null), which throws an exception. Is there is a way to set the value of sHTML programatically right after I initialize the browser?

    Code:
        Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Await initasync()
            Await initbrowser()
        End Sub
    
        Async Function initasync() As Task
            Await WebView21.EnsureCoreWebView2Async(Nothing)
        End Function
    
        Async Function initbrowser() As Task
            Await initasync()
            WebView21.CoreWebView2.Navigate("https://www.google.com/index.html")
        End Function
    
        Private Async Sub WebNavigation_Complete()
            Dim sHTML As String = Await WebView21.ExecuteScriptAsync("document.body.innerText;")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            WebNavigation_Complete()
        End Sub
    Last edited by pel11; Aug 28th, 2023 at 10:53 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width