CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    32

    Webbrouwser confirmation on use

    Hi. I'm, per suggestions, trying to use WebBrowser to scrap the company internal website for a project. I try to navigate to the website, but nothing happens. Here is my sequence and corresponding code.

    1) Instantiate the ClsBrowser from Form1, which the class ClsBrowser inherits WebBrowser.

    Code:
    Public Class ClsBrowser
    
        Inherits WebBrowser
    -------------------------------------------------------
        Private m_oBrowser As New ClsBrowser          <- In Form1
    2) try to launch the webbrowser with Navigate.

    Called from LoadBrowser function

    Code:
    :
                Navigate(cURL)
                Visible = True
    There is never a webpage that is launched, IE or Edge. Perhaps I'm expecting one when not everything has been processed/setup first, but my understanding is that this is all I need for a page to launch?

    Any suggestions? From what I found on the web this looks right, but there are many using the old ways so not sure if it's the same. i.e. CreateObject, SHDocVw.InternetExplorer, etc.


    I have looked around, but much has to do with starting the browser with.

    here is some more information about the project.


    What: The ClsBrowser already has all the functions needed for accessing the itmes I need to in the webbrowser page. For example here is the Logoff function.

    Loadbrowser navigate url, not that it will mean anything.

    Code:
                Navigate(cURL) ""https://epiq-prod.sjm.com/epiq_prod/reliance""

    Code:
       Public Function Logout(ByVal szELement As String) As Boolean
           Dim bStatus As Boolean
    
           Try
    
               'Assume a pass
               bStatus = False
    
               If (gEPIQ.GetIsDebug()) Then
                   Debug.Print("clsBrowser [Logout Enter]")
               End If
    
               'Click the CAPA operation button to expand for operation
               bStatus = PressButton(ENUM_ELEMENT.eELEMENT_ID, szELement)
    
               'Wait for browser
               BrowserWait()
    
               Logout = bStatus
    
               If (gEPIQ.GetIsDebug()) Then
                   Debug.Print("clsBrowser [Logout Exit]")
               End If
    
           Catch ex As Exception
               Dim szErr As String
               szErr = "Error occured for the following reason [" & ex.Message & "]"
               If (gEPIQ.GetIsDebug()) Then
                   Debug.Print(szErr)
                   gClsExcel.ExcelWriteErrorLog("Logout", szErr)
               End If
               Logout = True
           End Try
    
       End Function
    Here is the press button code.

    Code:
     Public Function PressButton(ByVal szElement As String, ByVal szElementName As String, Optional nNumItems As Integer = 0, Optional bKeyPress As Boolean = False, Optional bUseDLL As Boolean = False) As Boolean
    
         Dim HTMLobj As New Object
         Dim bStatus As Boolean
    
         'Handle any erros we may have cleanly
         Try
    
             If (gEPIQ.GetIsDebug()) Then
                 Debug.Print("clsBrowser [PressButton Enter]")
             End If
    
             If (gEPIQ.GetAbortRun()) Then
                 PressButton = True
                 HTMLobj = Nothing
                 Exit Function
             End If
    
             'Assume success
             bStatus = False
    
             '                       (nElement,  szElementName, Optional bGetItem,  Optional nID)
             HTMLobj = GetElement(szElement, szElementName)
    
             If (Not HTMLobj Is Nothing) Then
                 Sleep(200)
                 'bKeyPress to ClickElement
                 '
                 If (nNumItems = 0) Then
    
                     '               (HTMLobj, Optional bKeyPress, Optional bCloseDlg)
                     bStatus = ClickElement(HTMLobj, bKeyPress, bUseDLL)
    
                 ElseIf (nNumItems = 1 And HTMLobj.length = 1) Then
    
                     HTMLobj = GetElementItem(HTMLobj)
                 
                 else
    
      
                 End If
             Else
                 bStatus = True
             End If
    
             'Wait for browser
             BrowserWait()
    
             PressButton = bStatus
    
             If (gEPIQ.GetIsDebug()) Then
                 Debug.Print("clsBrowser [PressButton Exit]")
             End If
    
             'Release the object
             HTMLobj = Nothing
    
         Catch ex As Exception
             Dim szErr As String
             szErr = "Error occured for the following reason {" & ex.Message & "]"
             If (gEPIQ.GetIsDebug()) Then
                 Debug.Print(szErr)
                 gClsExcel.ExcelWriteErrorLog("PressButton", szErr)
             End If
             PressButton = True
             HTMLobj = Nothing
         End Try
    
     End Function
    So I have the routines setup to make life easier, for me, to just call a function to execute a button or checkbox.

    When: The loadbrowser function is called after some setup has taken place with the user telling me what type of function with the webpage they wish to do. Then the loadbrowser is launched with the "Option" they want to run that is used in later events.

    Code:
    Private Sub BTN_RUN_Click(sender As Object, e As EventArgs) Handles BTN_RUN.Click
    
        Dim lStatus As Long
        Dim nCount As Integer
        Dim nMenu As Integer
        Dim bRet As Boolean
        Dim szMenuSelection As String
        Dim clsSelection As New DLG_RUN_SELECTIION
    
        'BTN_RUN.Enabled = False
    
    
        Try
            If (GetIsDebug()) Then
                Debug.Print("gClsEPIQ [BTN_RUN_Click Enter]" & vbCrLf)
            End If
    
            If (GetAbortRun() = True) Then
                Exit Sub
            End If
    
            If (IsObjectConnected(GetBrowser()) = False) Then
                Exit Sub
            End If
    
            'InitializeProgressBar(14)
    
            UpdateRunControls(ENUM_RUN.eRUN_DISABLE_CTRLS, "Select the Run Option Desired ...", "BTN_RUN_Click")
            'LB_LIST_OF_FILES.Visible = False
    
            'clsSelection = New DLG_RUN_SELECTIION().ShowDialog()
            clsSelection.ShowDialog()
    
            SetRunOption(clsSelection.GetRunOption())
            clsSelection.Close()
    
            If (clsSelection.DialogResult = DialogResult.Cancel) Then
                Exit Sub
            End If
    
            If (LoadBrowser(GetRunOption()) = False) Then
    
            Else
                MsgBox("The Browswer could not be loaded, please contact support!", MsgBoxStyle.Critical, "Critical Error")
    
            End If
    Why: This is to interface with a company portal website in order to help speed up common tasks performed, such as pre-filing textboxes, checkboxes, comboboxes, etc. To help reduce the time it takes the person to fill out the form. This program is now being developed to automate closing over 7,000 records, so that a person, or persons, need to sit there and press 5 buttons to close out each of these ready for close records.
    Here is how LoadBrowser works.

    Code:
        Public Function LoadBrowser(ByVal nRunOption As Integer) As Boolean
    
            Dim bStatus As Boolean
    
            'Shell("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe -url " & cURL, vbNormalFocus)
    
            Try
    
                bStatus = False
    
                If (GetIsDebug()) Then
                    Debug.Print("gClsEPIQ [LoadBrowser Enter]" & vbCrLf)
                End If
    
                If (GetAbortRun()) Then
                    LoadBrowser = True
                    Exit Function
                End If
    
                If (IsObjectConnected(GetBrowser()) = False) Then
                    LoadBrowser = True
                    Exit Function
                End If
    
    
    
    
    
                InitializeProgressBar(0)
                UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPEN_BROWSER, "LoadBrowser")
                If (getBrowser.LoadBrowser() = False And GetAbortRun() = False) Then
    
                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_WAITING_FOR_LOGIN, CB_ASSIGNEE_NAME.Text)
                    If (getBrowser.PressButton(ENUM_ELEMENT.eELEMENT_ID, cID_LOGIN_BUTTON) = False And GetAbortRun() = False) Then
    
                        UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_PORTAL, cCOMPLAINTS_HANDLING)
                        If (getBrowser.PortalSelect(cID_PORTAL_COMPLAINTS) = False And GetAbortRun() = False) Then
    
    
                            Select Case nRunOption
    
                                Case ENUM_RUN.eRUN_NONRETURN
                                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_MENU, "Main Investigation")
                                    'Select the menu desired
                                    If (getBrowser.MenuSelect(cID_MENU_MAIN_ALL_BY_NUMBER) = False And GetAbortRun() = False) Then
                                    Else
    
                                    End If
    
                                Case ENUM_RUN.eRUN_REVIEW
    
                                Case ENUM_RUN.eRUN_ANALYSIS
    
                                Case ENUM_RUN.eRUN_NONCOMPLAINT_PIM
                                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_MENU, "Main Investigation")
                                    'Select the menu desired
                                    If (getBrowser.MenuSelect(cID_MENU_MAIN_ALL_BY_NUMBER) = False And GetAbortRun() = False) Then
                                    Else
    
                                    End If
    
                                Case ENUM_RUN.eRUN_CLOSE_PER
                                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_MENU, "Project Event Report")
                                    'Select the menu desired
                                    If (getBrowser.MenuSelect(cID_MENU_PER_ALL_BY_NUMBER) = True And GetAbortRun() = False) Then
    
                                    End If
    
                                Case ENUM_RUN.eRUN_MISSED_RISK_REVIEW
                                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_MENU, "Main Investigation")
                                    'Select the menu desired
                                    If (getBrowser.MenuSelect(cID_MENU_MAIN_ALL_BY_NUMBER) = False And GetAbortRun() = False) Then
                                    Else
    
                                    End If
    
                                Case ENUM_RUN.eRUN_NONCOMPLAINT_PIM
                                    UpdateRunControls(ENUM_RUN.eRUN_GENERIC_MESSAGE, cMSG_OPENING_MENU, "Main Investigation")
                                    'Select the menu desired
                                    If (getBrowser.MenuSelect(cID_MENU_MAIN_ALL_BY_NUMBER) = False And GetAbortRun() = False) Then
                                    Else
    
                                    End If
    ...
    Hopefully this was enough information to provide your feedback.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,902

    Re: Webbrouwser confirmation on use

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured