• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Can't initiate a click on a search button

shahin

Active Member
I'm trying to scrape a webpage with vba in combination with IE. The thing is i can fill in the required two search fields with my scraper but when i click on the search button, it throws an error as if i didn't put anything in the search boxes. It will be clearer when you see the below pictures. How can i initiate a click successfully?

Here is what I've tried so far:
Code:
Sub Get_Content()
    Dim ie As New InternetExplorer, html As HTMLDocument
    Dim itm As Object, post As Object, posts As Object

    With ie
        .Visible = True
        .navigate "https://brokercheck.finra.org/"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Set html = .document
    End With
  
    For Each itm In html.getElementsByTagName("input")
        If InStr(itm.placeholder, "Name or CRD#") > 0 Then
            itm.Value = "Michael John"
            Exit For
        End If
    Next itm
  
    For Each post In html.getElementsByTagName("input")
        If InStr(post.placeholder, "Firm Name or CRD# (optional)") > 0 Then
            post.Value = "Morgan Stanley"
            Exit For
        End If
    Next post
  
    Do While ie.Busy Or ie.readyState <> 4
        DoEvents
    Loop
  
    html.getElementsByClassName("md-button")(0).Click
  
    Do While ie.Busy Or ie.readyState <> 4
        DoEvents
    Loop
End Sub

Check out this two images:

Untitled.jpg Untitled1.jpg

Elements for the button:
Code:
<button class="md-raised md-primary md-hue-2 md-button md-ink-ripple" type="submit" ng-transclude="" aria-label="IndividualSearch"><div class="md-ripple-container" style=""></div></button>
 
Thanks for your comment Marc L. I tried manually and it never failed. However, when I try the same with my script, it doesn't work.
 
This is the only way I could find to click on the search button successfully.
Code:
Sub Get_Content_ano()
    Dim ie As New InternetExplorer, html As HTMLDocument
    Dim itm As Object, post As Object, posts As Object

    With ie
        .Visible = True
        .navigate "https://brokercheck.finra.org/"
        Do Until .readyState = READYSTATE_COMPLETE: Loop
        Set html = .document
    End With
  
    Set evt = html.createEvent("keyboardevent")
    evt.initEvent "change", True, False

    For Each itm In html.getElementsByTagName("input")
        If InStr(itm.placeholder, "Name or CRD#") > 0 Then
            itm.Value = "Michael John"
            Exit For
        End If
    Next itm
    itm.dispatchEvent evt
  
    For Each post In html.getElementsByTagName("input")
        If InStr(post.placeholder, "Firm Name or CRD# (optional)") > 0 Then
            post.Value = "Morgan Stanley"
            Exit For
        End If
    Next post
    post.dispatchEvent evt
  
    html.getElementsByClassName("md-button")(0).Click
    Do While ie.Busy Or ie.readyState <> 4: DoEvents: Loop

End Sub
 
Back
Top