0

I want to automate a repetitive process at work with VBA, and I want to click a button on the web-page, but I cannot seem to figure out how to do it, because the button does not have an ID. The html code for the button is highlighted in yellow on the attached image. Any help surmounting this hurdle would be greatly appreciated. Thanks in advanceenter image description here

QHarr
  • 83,427
  • 12
  • 54
  • 101
DoubleU
  • 95
  • 3
  • 10
  • Can you share what have you tried so far ? – Mikku Jun 06 '19 at 02:43
  • I have not tried much because I don't know what to do. I am new to VBA and HTML. Up until this point, I was able to use "getElementById" to get the element name and interact with it, but I am at a loss for what to do in this situation where I don't have an ID to work with. – DoubleU Jun 06 '19 at 03:03

2 Answers2

0

Try GetElementsByTagName("button").item(X).click

Where X is the number of the button element in the page design.

If the design is not very stable, you can loop through the button elements checking the class name and clicking the one that has calss name = ""

Set ButtonsElement = IE.document.GetElementsByTagName("button")
For i = 1 To ButtonsElement.length - 1
    If ButtonsElement.item(i).className = "" Then
        ButtonsElement.item(i).click
        Exit For
    End if
Next
Abdallah El-Yaddak
  • 440
  • 1
  • 9
  • 18
0

I would use an attribute = value selector with starts with operator, ^, to target the onclick attribute value by the substring at the start i.e. SelectListControl_ShowPopup.

ie.document.querySelector("[onclick^='SelectListControl_ShowPopup']").click
QHarr
  • 83,427
  • 12
  • 54
  • 101