I am trying to automate a process that involves running extracts against a large DB. For reasons out of my control I cannot simply access the database and run queries to get the information. I need to run a series of reports through a web front-end. This is a very time consuming manual process so automating it to run daily at 12:01am is my goal.
I have gotten most of the navigation down, but saving the report is very problematic. There is a html pop-up after you select export, it displays the count of exported records. Once it is done, you have to click download in the same window at which point the "File Download" windows from the browser is displayed. I want to click "Save". The "Save As" dialog is displayed and I want to edit the FileName in the only textbox in the window before clicking the "Okay" button.
What is have done thus far, is get the handle of the main IE window and maximize it. The html pop-up is always centered in the IE window, so I can move the cursor to the proper location. I have my code click the download button 1x every 5 seconds until the "File Download" window shows up.
The problem is that using FindWindowEX always seems to return a value even when the File Download window isn't opened. Worse, I'm not sure how to use that value to check the name of the window, or what the heck it is returning. I've included some output from the application after my "code".
I know the code as currently written will exit based on time have to avoid those infinite loops somehow.
Thanks for reading this far.
What I have tried:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
OpenRet = FindWindow(vbNullString, "SalesNumReg")
If OpenRet.ToInt64 > 0 Then
pRight = (Screen.PrimaryScreen.Bounds.Width) / 2
pBottom = (Screen.PrimaryScreen.Bounds.Height) / 2
While myCount < 24
Await System.Threading.Tasks.Task.Delay(5000)
Cursor.Position = New Point(pRight - 40, pBottom + 25)
LeftClick()
ChildRet = FindWindowEx(OpenRet, IntPtr.Zero, "File Download", vbNullString)
myCount += 1
Debug.Print(myCount & vbTab & ChildRet)
End While
End If
Debug Ouput
<br />
1 2382793880966791168<br />
2 2382796518076710912<br />
3 2382797209566445568<br />
4 2382797763617226752<br />
5 2382799099352055808<br />
6 2382799795136757760<br />
7 2382800349187538944<br />
8 2382801040677273600<br />
9 2382801981275111424<br />
10 32651964881829888<br />
11 32652007831502848<br />
12 30399774226120704<br />
13 30400457125920768