dcsimg
Results 1 to 6 of 6

Thread: web page download can't get click on save button to work!

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    web page download can't get click on save button to work!

    I access a web page via code and try to export and download an excel file. But at the usual 'Open Save Cancel' window I can't get the save button to fire!
    I found a few similar posts here but the solutions found don't work!

    Here is what I have !

    Code:
            Sub ClosePopup(ByVal WindowHandle As IntPtr)
    
            Dim clsChildHandles As ArrayList = GetChildWindowHandles(WindowHandle)
            Dim teststr As String
            Dim prthandleint As Long
            'look through all of the child handles of the window for an "Save" button (this method 
            'can also be used to gather more specific information about the dialog itself, such as 
            'the message being displayed)...
            For Each ptrHandle As IntPtr In clsChildHandles
                'if the Save button is found, click it...
                teststr = GetWindowText(ptrHandle)
                prthandleint = ptrHandle ' was having trouble with putting an intptr in debug.print!
                Debug.Print(teststr & " = Child TEXT:   len=" & teststr.Length & "handle = " & prthandleint & vbCrLf)
    
                If teststr.Contains("&Save") Then
                    ClickButton(ptrHandle)  ' THIS PART WORKS AS I GET HERE!
                    Exit For
                Else
                    Debug.Print(teststr & " = ELSE Child TEXT:   len=" & vbCrLf)
                End If
            Next
    
        End Sub
     
        Const BM_CLICK As Long = &HF5&
        Public Const WM_LBUTTONDOWN As UInteger = &H201
        Public Const WM_LBUTTONUP As UInteger = &H202
        Public Const WM_COMMAND As Integer = &H111         
    
    
      Sub ClickButton(ByVal WindowHandle As IntPtr)
    
     SendMessage(xAsIntPtr, BM_CLICK, &H83, WindowHandle) ' Sendmessage has no effect on File download window! 
    
    'I left in several flavors of the sendmessage that I've tried! 
            'SendMessageW(WindowHandle, WM_ACTIVATE, New IntPtr(WA_ACTIVE), IntPtr.Zero)
            'SendMessageW(WindowHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
            'SendMessage(WindowHandle, WM_LBUTTONDOWN, 0&, MakeLParam(180, 220))
            'SendMessage(WindowHandle, WM_LBUTTONUP, 0&, MakeLParam(180, 220))
           
        End Sub
    I've matched the handles with what I see using Spy++ . But I was wondering if I should see any activity on the save button with Spy++
    from the code activity like I do when I actually click on the button with a mouse?

    Appreciate any help in advance!

    Pete

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: web page download can't get click on save button to work!

    I'm including the message log file from Spy++
    Line 1-4 are the locate File Download window!
    Lines 5-38 is when SendMessageW(WindowHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero) fires
    Lines 39-42 is when Call SendMessage(WindowHandle, WM_LBUTTONDOWN, 0&, MakeLParam(180, 220)) fires
    Lines 43-46 is when Call SendMessage(WindowHandle, WM_LBUTTONUP, 0&, MakeLParam(180, 220)) fires.

    Hope this helps!


    <000001> 00CE079E S WM_GETTEXTLENGTH wParam:00000000 lParam:00000000
    <000002> 00CE079E R WM_GETTEXTLENGTH cch:5 [lResult:00000005]
    <000003> 00CE079E S WM_GETTEXT cchTextMax:12 lpszText:06909E04 [wParam:0000000C lParam:06909E04]
    <000004> 00CE079E R WM_GETTEXT cchCopied:5 lpszText:06909E04 ("&") [lResult:00000005]
    <000005> 00CE079E S BM_CLICK wParam:00000000 lParam:00000000
    <000006> 00CE079E S WM_LBUTTONDOWN fwKeys:0000 xPos:39 yPos:11 [wParam:00000000 lParam:000B0027]
    <000007> 00CE079E S WM_GETDLGCODE wParam:00000000 lParam:00000000
    <000008> 00CE079E R WM_GETDLGCODE fuDlgCodeLGC_UNDEFPUSHBUTTON | DLGC_BUTTON [lResult:00002020]
    <000009> 00CE079E S WM_GETDLGCODE wParam:00000000 lParam:00000000
    <000010> 00CE079E R WM_GETDLGCODE fuDlgCodeLGC_UNDEFPUSHBUTTON | DLGC_BUTTON [lResult:00002020]
    <000011> 00CE079E S BM_SETSTYLE dwStyle:BS_DEFPUSHBUTTON | BS_TEXT | 0000 | 0000 | 0000 fRedraw:True [wParam:00000001 lParam:00000001]
    <000012> 00CE079E S WM_STYLECHANGING wStyleType:GWL_EXSTYLE | GWL_STYLE lpss:0690A2B4 [wParam:FFFFFFF0 lParam:0690A2B4]
    <000013> 00CE079E R WM_STYLECHANGING lResult:00000000
    <000014> 00CE079E S WM_STYLECHANGED wStyleType:GWL_EXSTYLE | GWL_STYLE lpss:0690A2B4 [wParam:FFFFFFF0 lParam:0690A2B4]
    <000015> 00CE079E R WM_STYLECHANGED lResult:00000000
    <000016> 00CE079E R BM_SETSTYLE lResult:00000000
    <000017> 00CE079E S WM_IME_SETCONTEXT fSet:1 iShow:C000000F [wParam:00000001 lParam:C000000F]
    <000018> 00CE079E S WM_IME_NOTIFY dwCommand:IMN_OPENSTATUSWINDOW dwCommand:00000002 dwData:00000000 [wParam:00000002 lParam:00000000]
    <000019> 00CE079E R WM_IME_NOTIFY lResult:00000000
    <000020> 00CE079E R WM_IME_SETCONTEXT lResult:00000000
    <000021> 00CE079E S WM_SETFOCUS hwndLoseFocus:00250756 [wParam:00250756 lParam:00000000]
    <000022> 00CE079E R WM_SETFOCUS lResult:00000000
    <000023> 00CE079E S WM_KILLFOCUS hwndGetFocus:00CE079E [wParam:00CE079E lParam:00000000]
    <000024> 00CE079E S BM_SETSTATE fState:False [wParam:00000000 lParam:00000000]
    <000025> 00CE079E R BM_SETSTATE lResult:00000000
    <000026> 00CE079E S WM_CAPTURECHANGED hwndNewCapture:00000000 [wParam:00000000 lParam:00000000]
    <000027> 00CE079E R WM_CAPTURECHANGED lResult:00000000
    <000028> 00CE079E R WM_KILLFOCUS lResult:00000000
    <000029> 00CE079E S WM_IME_SETCONTEXT fSet:0 iShow:C000000F [wParam:00000000 lParam:C000000F]
    <000030> 00CE079E R WM_IME_SETCONTEXT lResult:00000000
    <000031> 00CE079E S WM_IME_SETCONTEXT fSet:1 iShow:C000000F [wParam:00000001 lParam:C000000F]
    <000032> 00CE079E R WM_IME_SETCONTEXT lResult:00000000
    <000033> 00CE079E S WM_SETFOCUS hwndLoseFocus:00CE079E [wParam:00CE079E lParam:00000000]
    <000034> 00CE079E R WM_SETFOCUS lResult:00000000
    <000035> 00CE079E R WM_LBUTTONDOWN lResult:00000000
    <000036> 00CE079E S WM_LBUTTONUP fwKeys:0000 xPos:39 yPos:11 [wParam:00000000 lParam:000B0027]
    <000037> 00CE079E R WM_LBUTTONUP lResult:00000000
    <000038> 00CE079E R BM_CLICK lResult:00000000
    <000039> 00CE079E S WM_LBUTTONDOWN fwKeys:0000 xPos:-20480 yPos:1680 [wParam:00000000 lParam:0690B000]
    <000040> 00CE079E S BM_SETSTATE fState:False [wParam:00000000 lParam:00000000]
    <000041> 00CE079E R BM_SETSTATE lResult:00000000
    <000042> 00CE079E R WM_LBUTTONDOWN lResult:00000000
    <000043> 00CE079E S WM_LBUTTONUP fwKeys:0000 xPos:-20480 yPos:1680 [wParam:00000000 lParam:0690B000]
    <000044> 00CE079E S WM_CAPTURECHANGED hwndNewCapture:00000000 [wParam:00000000 lParam:00000000]
    <000045> 00CE079E R WM_CAPTURECHANGED lResult:00000000
    <000046> 00CE079E R WM_LBUTTONUP lResult:00000000




    Pete
    Last edited by peterg2000; Aug 21st, 2019 at 09:10 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: web page download can't get click on save button to work!

    This the Spy++ log when I actually click on the Save button with the mouse!

    <000001> 00CE079E S WM_MOUSEACTIVATE hwndTopLevel:003A0764 nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN [wParam:003A0764 lParam:02010001]
    <000002> 00CE079E R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE [lResult:00000001]
    <000003> 00CE079E S BM_SETSTYLE dwStyle:BS_DEFPUSHBUTTON | BS_TEXT | 0000 | 0000 | 0000 fRedraw:True [wParam:00000001 lParam:00000001]
    <000004> 00CE079E R BM_SETSTYLE lResult:00000000
    <000005> 00CE079E P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:39 yPos:6 [wParam:00000001 lParam:00060027 time:475:02:59.156 point1016, 540)]
    <000006> 00CE079E S BM_SETSTATE fState:True [wParam:00000001 lParam:00000000]
    <000007> 00CE079E R BM_SETSTATE lResult:00000000
    <000008> 00CE079E S BM_SETSTATE fState:True [wParam:00000001 lParam:00000000]
    <000009> 00CE079E R BM_SETSTATE lResult:00000000
    <000010> 00CE079E P WM_LBUTTONUP fwKeys:0000 xPos:39 yPos:6 [wParam:00000000 lParam:00060027 time:475:02:59.281 point1016, 540)]
    <000011> 00CE079E S BM_SETSTATE fState:False [wParam:00000000 lParam:00000000]
    <000012> 00CE079E R BM_SETSTATE lResult:00000000
    <000013> 00CE079E P WM_MOUSELEAVE wParam:00000000 lParam:00000000 time:475:03:00.281 point1016, 561)
    <000014> 00CE079E P WM_MOUSELEAVE wParam:00000000 lParam:00000000 time:475:03:11.937 point993, 529)
    <000015> 00CE079E S WM_MOUSEACTIVATE hwndTopLevel:003A0764 nHittest:HTCLIENT uMsg:WM_LBUTTONDOWN [wParam:003A0764 lParam:02010001]
    <000016> 00CE079E R WM_MOUSEACTIVATE fuActivate:MA_ACTIVATE [lResult:00000001]
    <000017> 00CE079E P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:41 yPos:6 [wParam:00000001 lParam:00060029 time:475:03:14.265 point1018, 540)]
    <000018> 00CE079E S BM_SETSTATE fState:True [wParam:00000001 lParam:00000000]
    <000019> 00CE079E R BM_SETSTATE lResult:00000000
    <000020> 00CE079E P WM_LBUTTONUP fwKeys:0000 xPos:41 yPos:6 [wParam:00000000 lParam:00060029 time:475:03:14.406 point1018, 540)]
    <000021> 00CE079E S BM_SETSTATE fState:False [wParam:00000000 lParam:00000000]
    <000022> 00CE079E R BM_SETSTATE lResult:00000000


    Pete

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,991

    Re: web page download can't get click on save button to work!

    If there is any alternative to the web page, then use it. Automating anything off a web page is painful (as you are finding), and subject to frequent change. If the site wants you to get the data (and one can assume that they do, since they make it available), they may offer up an API or web service that supplies the data. If they don't, then they may well be willing to do so if asked. Such a solution would be VASTLY superior to automating a web page in every circumstance, so it's worth a look.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: web page download can't get click on save button to work!

    Quote Originally Posted by Shaggy Hiker View Post
    If there is any alternative to the web page, then use it. Automating anything off a web page is painful (as you are finding), and subject to frequent change. If the site wants you to get the data (and one can assume that they do, since they make it available), they may offer up an API or web service that supplies the data. If they don't, then they may well be willing to do so if asked. Such a solution would be VASTLY superior to automating a web page in every circumstance, so it's worth a look.
    Unfortunately I have to do it this way as the admins of the site are very restrictive. According to them we are VERY fortunate to get the report at all!

    Pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: web page download can't get click on save button to work!

    Found the solution myself!

    Needed to put setactiveWindow in first!

    SetActiveWindow(xAsIntPtr)
    SendMessageW(WindowHandle, WM_ACTIVATE, New IntPtr(WA_ACTIVE), IntPtr.Zero)
    SendMessageW(WindowHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero)

    Pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width