-1

I am trying to run a vba code that: 1 - access a site (https://www.protestosp.com.br/consulta-de-protesto/) 2 - enter some information 3 - Click on a button "Consultar" (here is the problem)!

Problem description: I am not able to click on the button (I am thinking this is not a button, but I dont really know).

<input class="btn-padrao blue borderEffect2 mt-3 hoverEffect wider3" type="button" onclick="ValidarConsulta(this);" value="CONSULTAR">

in my current code, i am using:

```Set frm = IE.Document.GetElementsByclass("btn-padrao blue borderEffect2 mt-3 hoverEffect wider3")
frm.submit```
1
  • Probably a good idea to show us the code you used to try to click the button. Difficult for us to guess the problem otherwise (and your question will likely get closed) Oct 20, 2020 at 23:20

1 Answer 1

0

I suggest trying to loop through input elements on the page and check its value. If the value is CONSULTAR then try to click it.

Example VBA code:

Sub demo()

    Dim IE  
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "https://Your_URL_will_be_here..."

    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
     
   Set clickEvent = IE.document.createEvent("HTMLEvents")
   clickEvent.initEvent "click", True, False
   
   Set elem1 = IE.document.getElementById("AbrangenciaNacional")
   elem1.Click
   elem1.dispatchEvent clickEvent
   
   IE.document.getElementById("TipoDocumento").Value = "2"
   
   IE.document.getElementById("Documento").Value = "12345"

   'Below is code to loop through inputs, find the button and click it.
    Set elems = IE.document.getElementsByTagName("input")
    For Each elem In elems
        If (elem.Value) = "CONSULTAR" Then
            elem.Click
            elem.dispatchEvent clickEvent
            Exit For
        End If
    Next elem

End Sub 

Output:

enter image description here

You can see that code is clicking the CONSULTAR button and the page is showing the error because the Document number is not valid.

You can try to pass the correct values and try to test this code on your side.

1
  • actually, the code was perfect. I made some changes for what I nedded (add a loop to search a batch of"cnpj" and colect it results :D Many thanks! Oct 22, 2020 at 2:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.