Consulting

Results 1 to 5 of 5

Thread: Automate IE webpage booking

  1. #1

    Automate IE webpage booking

    Hello,

    I am trying to automate an online booking using Excel & VBA. I have little experience with VBA code. So far I am able to open a IE window, click the login drop down button, enter my username & password in the two fields and then click the login button. This process seems to be working fine, however when I get to the second page after login, I'm having trouble clicking another menu button to continue on in the booking. Here is my VBA code:

    Sub GetIE()
      Dim IE As Object
      Set IE = CreateObject("InternetExplorer.Application")
      IE.Visible = True
      IE.Navigate "URL Of The Website" '
      
     
    ' Wait while IE loading...
    Do
    DoEvents
    Loop Until IE.ReadyState = 4
     
    'Clicks the SIGN IN button on the main menu - drop down window appears
    IE.document.getElementById("sign-in-menu-btn").Click
    
    'Enters the username into username field
    IE.document.getElementById("Username").Value = "my_email_address" '
    
    'Enters the Password into Password field
    IE.document.getElementById("Password").Value = "my_password"
        
        
    'clicks SIGN IN after login info
    Set AllHyperLinks = IE.document.getElementsByTagName("A")
            For Each hyper_link In AllHyperLinks
            
                If hyper_link.href = "javascript:signIn()" Then
                    hyper_link.Click
                    Exit For
                End If
            Next hyper_link
       
    
    End Sub

    The next button that I am trying to click has the HTML code of this:

    HTML Code:
    <a class="anchorbutton gray vertical" onclick="this.blur();" href="example_link">Book a Tee Time</a>
    Thanks for any assistance.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Why Click? After Sign In, repeat the Wait loop, then IE.Navigate "URL Example_Link".
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Thanks, that worked. I added another wait loop and then copied the new URL link.
    Is there a way to open the link in the same internet explorer window?

    Here is the next section of code I used:

    ' Wait while IE loading...
    Do
    DoEvents
    Loop Until IE.ReadyState = 4
      
    
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "URL of second page "

  4. #4
    I am also having trouble trying to click a Div Class ID.


    I have tried this code, but get the Runtime error 424 (Object Required):
    IE.document.getElementById("PRGEF2021-05-02-08.33.00.00018").Click
    Here is the HTML of the CSS button I am trying to click:
    HTML Code:
    <div class="search-results-tee-times-box eighteen-holes PRGE-box" id="PRGEF2021-05-02-08.33.00.00018" style="height: 153.3px;" onclick="isNotLocked('PRGE', 'F', '2021-05-02', '08:33', 18, 1, function() { document.getElementById('Players').value='';loadGenericMessage102Popup(function() { unlockBooking('PRGE', 'F', '2021-05-02', '08:33') }, getPopupTop('PRGEF2021-05-02-08.33.00.00018') );scrollSize102(); }, false, 'PRGEF2021-05-02-08.33.00.00018')">
    <p class="time">
    8:33<span class="am-pm">am</span>
    </p>
    <p class="price"></p>
    <p class="item-description-PRGE item-description" style="height: 0px;"></p>
    <a class="anchorbutton players-holes-button-50" href="javascript:void(0)">
    <div class="players-allowed">
    1 Player
    </div>
    <div class="booking-holes">18 Holes</div>
    <div class="right-arrow"></div>
    </a>
    <script type="text/javascript">
    document.getElementById("PRGEF2021-05-02-08.33.00.00018").setAttribute("onclick", "isNotLocked('PRGE', 'F', '2021-05-02', '08:33', 18, 1, function() { document.getElementById('Players').value='';loadGenericMessage102Popup(function() { unlockBooking('PRGE', 'F', '2021-05-02', '08:33') }, getPopupTop('PRGEF2021-05-02-08.33.00.00018') );scrollSize102(); }, false, 'PRGEF2021-05-02-08.33.00.00018')");
    </script>
    </div>

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Is there a way to open the link in the same internet explorer window?
    I would think that you just reuse the original object:
    ' Wait while IE loading...
    Do
    DoEvents
    Loop Until IE.ReadyState = 4
    IE.navigate "URL of second page"
    I haven't done any HTM coding in a dozen years and have never used JavaScript. I imagine something like
    document.getElementById("PRGEF2021-05-02-08.33.00.00018").Click
    Rememeber, you're using VBA to operate on (IE) Objects modifed by js, so it might be as simple as
    IE.Elements("PRGEF2021-05-02-08.33.00.00018").Click
    OTOH, you may have to set the Element's Attributes before "clicking".
    See JavaScript For Dummies and the IE VBA Object model
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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