Search code examples
htmlvbaclassinternet-explorerhref

Can i click on a button by de href or the class?


I'm current trying to click on a button but it has no id or class name, just class and href.

The html code is:

<a href="#" class="bt-acessar-login radius" onclick="validarFornecedor()" ;="">
  <i></i>
  <span>Acessar sistema</span>
  <div class="clear"></div>
 </a>

And the vba code I tried is:

Set btnObject = .document.getElementByClass("bt-acessar-login radius")
btnObject.FireEvent ("onclick")

Solution

  • i search some more and find this code who works for me !

    Set elems = .document.getElementsByClassName("bt-acessar-login radius")
            For Each e In elems
            If (e.getAttribute("onclick") = "validarFornecedor()") Then
                e.Focus
                e.Click
                Exit For
            End If
            Next e