0

I am new to VBA. I am trying to click on the "GO" search button after I logged in to a secured website.

I tried many ways to click on the button, but I got no luck.

Here is the inspect element.

<button class="button primary pull-right" ng-click="search()" ng-disabled="searchForm.$invalid">
    Go <i class="glyphicon glyphicon-chevron-right"></i>
</button>

Here is what I have tried.

Method 1

Set HTMLDoc = HTMLDoc.class("button primary pull-right").document
Set button = HTMLDoc.getElementsByTagName("BUTTON")(0)   'first button
button.Click

For i = 1 To 5
button.Click
DoEvents
Next

Method 2

For Each hyper_link In allhyperlinks
If hyper_link.class = "button primary pull-right" Then
       hyper_link.Click
       Exit For
  End If
Next hyper_link

Method 3

Set allhyperlinks = IE.document.getElementsByTagName("button")
For Each hyper_link In allhyperlinks
If hyper_link.getAttribute("class") = "search" Then
hyper_link.Click
Exit For
End If
Next

Method 4

Dim oHTML_Element As IHTMLElement
Dim oBrowser As InternetExplorer
Dim ie As Variant

For Each oHTML_Element In ie.document.getElementsByName("button")
If oHTML_Element.className = "button primary pull-right" Then
    oHTML_Element.Click
End If
Next

Method 5

     Set ie = CreateObject("InternetExplorer.Application")
     With ie
    Do Until .readyState = 4
    DoEvents
    Loop

    Application.Wait (Now + TimeValue("0:00:15"))
        ie.document.getElementsByClassName("button primary pull-right").Click
    Application.Wait (Now + TimeValue("0:00:1"))

End With

Method 6

Set ie = CreateObject("InternetExplorer.Application")
ie.document.getElementByClassName("button primary pull-right")(0).Click

Any help would be greatly appreciated.

Thank you!

2 Answers2

1

I presume you have not given url because it is beyond a login. That makes solving ten times harder. Nevertheless some points.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
  • Thanks for spending time to answer my question. Here is an example. This is from the www.jetblue.com. If I want to hit the "Find it" button using VBA. How should I modify the code? Here is the inspect element. – Rachael Chan Mar 10 '18 at 00:48
0

Try this code

Sub Test()
Dim ie          As Object
Dim e           As Object

Set ie = CreateObject("InternetExplorer.Application")

With ie
    .Visible = True
    .navigate "www.jetblue.com"
    Do Until .readyState = 4: DoEvents: Loop

    For Each e In .document.getElementsByTagName("input")
        If e.ID = "email_field" Then
            e.Value = "your email"
        ElseIf e.ID = "password_field" Then
            e.Value = "your password"
        End If
    Next e

    For Each e In .document.getElementsByTagName("input")
        If e.ID = "signin_btn" And e.Type = "submit" Then e.Click: Exit For
    Next e
End With
End Sub
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
  • Thanks for spending time on looking into this. I had no problem to sign in with my log in and password. My question is, how to hit "FIND IT" on the jetblue.com. The "Find It" button is running Angular. – Rachael Chan Mar 12 '18 at 16:13