I have a code which is automating Internet Explorer, with IE visibility set to false so that the code operates in the background. My code clicks an element ID which opens a separate IE window which is visible and contains a PDF report. Unfortunately, I have been unable to get the new IE window to open but remain invisible and download a copy of the PDF to the computer desktop.
I have tried navigating directly to the link of the newly opened page with the report however the link can vary.
I am clicking element "btnContinue" on the site to open the report:
<input name="btnContinue" class="btn btn-primary" id="btnContinue" onclick="javascript:pop('Splash.aspx?SplashID=3&../Reports/View.aspx&ReporttypeID=1&lang=EN&ruletypeid=5&ruleid=0'); return false;" type="submit" value="Continue">
Here is my code:
Sub navigate()
Const url = "https://myURL"
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie 'Open IE
.navigate url
ieBusy ie
.Visible = False
If Item.ID = "btnNextPage" Then
Item.Click
Exit For
End If
Next
ieBusy ie
‘Below code clicks the element ID and opens a new IE with the report – Code needs to open a new IE but visibility remain false and download the newly opened report OR report triggered to be downloaded directly from element/javascript onclick.
For Each Item In ie.document.all
If Item.ID = "btnContinue" Then
Item.Click
Exit For
End If
Next
ieBusy ie
End With 'End IE actions
End Sub
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.ReadyState < 4
DoEvents
Loop 'Loop
End Sub
I need this code to open the new page, remain invisible, and download the PDF to the desktop OR somehow trigger the report to download from the onclick (if possible) without needing to open the new page from clicking the element. I have tried to navigate/trigger the javascript onclick event to see if the report can be downloaded directly, without clicking the element to open the report in a new window but unfortunately not having any success. Any help would be greatly appreciated.