none
VBA code to handle WEB PAGE Dialog box RRS feed

  • Question

  • Hi,

    I am working on web scrapping project and i need a code which will help me to handle the Web Page Dialog box Control.

    So that i can pull the information which is present on the WEB Page Dialog.

    Now i am unable to get the reference to WEB Page Dialog.

    Because the Dialog box appears out side of brower window .

    Thanks,

    Regards,

    Kiran Kumar Gunti.


    Tuesday, November 11, 2014 6:54 PM

All replies

  • Hi,

    I am working on web scrapping project and i need a code which will help me to handle the Web Page Dialog box Control.

    So that i can pull the information which is present on the WEB Page Dialog.

    Now i am unable to get the reference to WEB Page Dialog.

    Because the Dialog box appears out side of brower window .

    Thanks,

    Regards,

    Kiran Kumar Gunti.


    Maybe this thread can lead you to a solution. I believe the trick is to capture the window with an API call.

    Handling dialog boxes in IE automation

    Also check this thread for the GetWindow API call:

    Find a window using GetWindow

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Tuesday, November 11, 2014 8:04 PM
    Moderator
  • Thanks

    I will check below code.

    ' Find the target window and minimize, maximize,
    ' or restore it.
    Private Sub cmdGo_Click()
    Dim action As Long
    Dim target As String
    Dim app_hwnd As Long
    Dim wp As WINDOWPLACEMENT
    
        ' Set the appropriate action.
        If optPlacement(0).Value Then
            ' Minimize.
            action = SW_SHOWMINIMIZED
        ElseIf optPlacement(1).Value Then
            ' Maximize.
            action = SW_SHOWMAXIMIZED
        Else
            ' Restore.
            action = SW_SHOWNORMAL
        End If
    
        ' Get the first window.
        target = txtTargetName.Text
        app_hwnd = GetWindow(GetDesktopWindow(), GW_CHILD)
    
        ' Examine the windows.
        Do While app_hwnd <> 0&
            ' See if this is a top level window.
            If IsTopLevelWindow(app_hwnd) Then
                ' See if the window's text has the target in it.
                If InStr(WindowText(app_hwnd), target) > 0 Then
                    ' Get the window's current placement.
                    wp.length = Len(wp)
                    GetWindowPlacement app_hwnd, wp
    
                    ' Perform the action.
                    wp.showCmd = action
                    SetWindowPlacement app_hwnd, wp
                End If
            End If
    
            ' Get the next window.
            app_hwnd = GetWindow(app_hwnd, GW_HWNDNEXT)
        Loop
    End Sub
    
    ' Return True if this is a top level window.
    Private Function IsTopLevelWindow(ByVal app_hwnd As Long) _
        As Boolean
        ' Assume the window is not top level.
        IsTopLevelWindow = False
    
        ' See if the window's text is blank.
        If Len(WindowText(app_hwnd)) = 0 Then Exit Function
    
        ' See if the window is visible.
        If IsWindowVisible(app_hwnd) = 0 Then Exit Function
    
        ' See if the window has an owner.
        If GetWindow(app_hwnd, GW_OWNER) <> 0& Then Exit _
            Function
    
        ' The window has non-blank text, is visible, and has
        ' no owner so it is (probably) a top level window.
        IsTopLevelWindow = True
    End Function
    
    ' Return the window's text.
    Private Function WindowText(ByVal app_hwnd As Long) As _
        String
    Dim text_len As Long
    Dim window_text As String
    
        text_len = GetWindowTextLength(app_hwnd)
        window_text = Space$(text_len + 1)
    
        text_len = GetWindowText(app_hwnd, window_text, _
            text_len + 1)
        WindowText = Left$(window_text, text_len)
    End Function

    hi

    Tuesday, November 11, 2014 8:36 PM
  • The above code is not working

    I am geting errors

    Example

    GetWindowTextLength()

    for above function

    User defined not found

    GetWindowText()

    for above function

    User defined not found

    For other also i am getting same error

    Thanks and Regards,

    Kiran Kumar Gunti


    hi

    Tuesday, November 11, 2014 9:18 PM
  • The above code is not working

    I am geting errors

    Example

    GetWindowTextLength()

    for above function

    User defined not found

    GetWindowText()

    for above function

    User defined not found

    For other also i am getting same error

    Thanks and Regards,

    Kiran Kumar Gunti


    hi

    It looks like some API's are missing, as its not declared in above code, try to add this at the beginning of the code:

    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

    and this one as well:

    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Tuesday, November 11, 2014 10:22 PM
    Moderator
  • Sir,

    Above code has some issues

    Can you please guide me how to read the data from web page dialog box.

    I am working on web scraping project and when we are running web application with some input

    The out put information is shown on a web page dialog box this is out side of web browser and we are not able to get source html code information for this window(it is modal window, modal.jsp)

    Please can you help with this.

    Thanks,

    Kiran Kumar Gunti


    hi


    Thursday, November 13, 2014 2:34 PM
  • Any alternate please reply

    hi

    Tuesday, November 18, 2014 5:21 PM