1

I need to scrape an internal company site to extract some buried data. In order to do this, I need to click through a number of buttons to access each record. I am having trouble getting VBA to click one of the buttons on the page in question.

This is the button I'm trying to click:

<button type="button" tabindex="0" class="StandardButton OptionsButton" value="Options ▼" id="DDMenuaB823456B43A2C4C1AABF2" onclick="lastMenuEntered='823456B43A2C4C1AABF2';enterMenu(this,'823456B43A2C4C1AABF2','','1110111');this.focus();" onblur="{setTimeout(function() {leaveMenu(this,'823456B43A2C4C1AABF2');},200)}"> <span style="color:#0069A5;text-justify:distribute-all-lines;" class="fa fa-lg fa-cog"></span><span class="OptionsText">Options ▼</span></button>

I am trying to access it via class="StandardButton OptionsButton" but without success.

I have been working on this for a couple of days (new to VBA). I tried following Clicking a button in Internet Explorer using VBA (getElementsByClassName) as well as various other solutions here but with no success.

Dim rowsonpage As Integer 'integer variable we'll use as a counter
Dim optbtn As HTMLInputButtonElement    
For rowsonpage = 1 To 20 'loop 20 rows per page
   'click options
    Set optbtn = objIE.document.getElementsByClassName("StandardButton OptionsButton")(1)
    optbtn.Click
        For Each btn In optbtn
            btn.Click
            Exit For
        Next
Next rowsonpage

I'm getting Run-time error 91 with this code.

I've also tried with this (and many other permutations):

For Each aInput In objIE.document.getElementsByClassName("StandardButton OptionsButton")
If aInput.getAttribute("value") = "Options" Then
    aInput.Click
    Exit For
End If
Next aInput

Which doesn't give any errors, but does not click the button.

Any help greatly appreciated.

Edit: I forgot to mention that I will need to loop through 20 of these elements per page, times around 700 pages - each with a different id attribute, but with the same class names - hence wanting to select by class, not id. Any other ideas? Thanks for the comments so far.

1
  • 1
    If there is an id attribute, which there is, always use that as in theory it should be a faster method. Also, nicely written question so +1 Commented Jan 10, 2019 at 8:20

1 Answer 1

1

Try this

IE.document.getElementById("DDMenuaB823456B43A2C4C1AABF2").click()

Or

IE.document.getElementById("DDMenuaB823456B43A2C4C1AABF2").FireEvent("onclick")

Sign up to request clarification or add additional context in comments.

1 Comment

Also try IE.document.querySelector("#DDMenuaB823456B43A2C4C1AABF2").click

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.