How to click a button on a webpage

Excel_Phil

New Member
Joined
Sep 9, 2013
Messages
3
Hello everyone, I'm trying to use a macro to click on a button on this site: https://sms.comtele.com.br/ - the button is called "conectar".

I cant seem to get right code that dentifies the button "conectar" on the HTML code and put it to be clicked in my macro.

I appreciate any help!

Thanks in advance!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Oi, the below seemed to work for me. Although I've never looked at html before

Rich (BB code):
Private Sub IE_Autiomation()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    ' You can uncoment Next line To see form results
    IE.Visible = False
 
    ' Send the form data To URL As POST binary request
    IE.Navigate "https://sms.comtele.com.br/"
 

 
    ' Wait while IE loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
 
   
 
    Set objCollection = IE.document.getElementsByTagName("input")
 
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "Username" Then
 
            ' Set text for search
            objCollection(i).Value = "Barry"
 
        Else
            If objCollection(i).Type = "password" And _
               objCollection(i).Name = "Password" Then
               objCollection(i).Value = "Password"
 
                ' "Search" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
   Set ElementCol = IE.document.getElementsByClassName("btn btn-success")
For Each btnInput In ElementCol
    btnInput.Click
 Next btnInput
    
    ' Wait while IE re-loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
 
    ' Show IE
    IE.Visible = True
 
    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
 

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,196,007
Messages
6,012,825
Members
441,731
Latest member
jonceramic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top