Help with HTML <button>

bloodymax

New Member
Joined
Sep 29, 2017
Messages
4
Hi guys, I cant seem to figure out how to add a .click on this HTML code.

Normally I would just use getelementbyid("1234").click

but there is no "id" that I can find. all I can find is an HTML code with
HTML:
<button>
I just want to click the Vote Button
Help me please.

Currently this is my code

objIE.document.getElementById("option-49").Click
objIE.document.getElementsByClassName("btn btn-default vote-button weblator-poll-submit").Click
Application.Wait (Now + TimeValue("0:01:00"))

this is the HTML code
HTML:
<div class="button-vote">
<button class="btn btn-default vote-button weblator-poll-submit"><i class="fa fa-spinner fa-spin vote-spin"></i> Vote</button>   </div>
<div class="weblator-view-results"><a href="#" class="weblator-view-poll btn btn-default">Show</a><a href="#" class="weblator-hide-poll btn btn-default">Hide</a>  </div>

Thanks in advance
 
Last edited by a moderator:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try:
Code:
objIE.document.getElementsByClassName("btn btn-default vote-button weblator-poll-submit")(0).Click
 
Upvote 0
heres the code

<
div class="button-vote">

<button class="btn btn-default vote-button weblator-poll-submit"><i class="fa fa-spinner fa-spin vote-spin"></i> Vote</button>
<div class="weblator-view-results"><a href="#" class="weblator-view-poll btn btn-default">Show</a><a href="#" class="weblator-hide-poll btn btn-default">Hide</a>
</div>

 
 
Upvote 0
Hi bloodymax,

I used below code for change event for html page, try to incorporate this code into your code and make some changes accordingly like you can try "change" to click something like that.

Code:
Sub NavigateIt1()
    
    Dim oIE As Object
    Dim AvailableLinks
    Dim objEvent
    
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.navigate ("https://uk.investing.com/indices/us-spx-500-historical-data")
    oIE.Visible = True


    Do
        DoEvents
    Loop Until oIE.readyState = 4
    
    Set AvailableLinks = oIE.document.getElementById("data_interval")
    
    'Selecting Monthly options here
    AvailableLinks.selectedIndex = 2
    
    'Here we are firing "change" event
    Set objEvent = oIE.document.createEvent("HTMLEvents")
    objEvent.initEvent "change", False, True
    AvailableLinks.dispatchEvent objEvent
    
    Application.Wait (Now() + TimeValue("00:00:06"))
 
    MsgBox "Hi"




End Sub

Thanks
Kashif
 
Upvote 0
Hi Kashif,
my knowledge with vba is on a novice level. I have never used createEvent before. what does it exactly do?
ive googled it around and im strugging to wrap it around my head.

thanks
Bloodymax
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,218
Members
453,024
Latest member
Wingit77

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
Back
Top