I have written some VB.Net
code using WebView2
control to try to download a PDF file from a specific magazine.
My VB.Net
code is following
Imports Microsoft.Web.WebView2.Core
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Call InitializeAsync()
End Sub
Async Sub InitializeAsync()
Await wv.EnsureCoreWebView2Async()
wv.CoreWebView2.Navigate("https://journal.cinetelerevue.sudinfo.be")
End Sub
Private Sub wv_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles wv.NavigationCompleted
Threading.Thread.Sleep(1000)
Call ClickOnPdfButton()
Threading.Thread.Sleep(1000)
End Sub
Async Sub ClickOnPdfButton()
Dim sButtonCmd = "document.getElementById('readPdfBtn').click();"
Dim task = Await wv.ExecuteScriptAsync(sButtonCmd)
End Sub
End Class
The first Navigate()
method display correctly requested URL.
The Javascript document.getElementById('readPdfBtn').click();
method works also correclty. It open a NEW window because Javascript code linked to click()
method do following action
var e = window.open("","pdf_view");
When program has run, I obtain following result
I have painted a red circle around PDF
button in first Window.
My problem is that I need to continue to click on another PDF
button contained in new Window to initiate PDF download.
How can I access it using wv
WebView2 variable ?
In tasks manager, I can see that new Windows is attached to Extract-PDF-From-Web
application that is the name of my VB.Net
application.