Option Explicit On
Option Strict On

Imports Microsoft.Web.WebView2.Core
Imports Microsoft.Web.WebView2.WinForms

Public Class Form1

    Private WithEvents WebView2 As New WebView2
    Private AutoInput As New WebView2OpenDialogAutomaticInput

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WebView2.Dock = DockStyle.Fill
        Me.Controls.Add(Me.WebView2)
        Me.InitializeAsync()
    End Sub

    Private Async Sub InitializeAsync()
        Await Me.WebView2.EnsureCoreWebView2Async(Nothing)
        Me.AutoInput.WaitDialogOpen(Application.ExecutablePath)
        Dim source As String = "<input type=""file"" id=""upload"">"
        Me.WebView2.NavigateToString(source)
    End Sub

    Private Async Sub WebView2_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles WebView2.NavigationCompleted
        Dim Script As String = "
            var button = document.getElementById('upload');
            button.click();"
        Await Me.WebView2.ExecuteScriptAsync(Script)
    End Sub

End Class