Reputation: 27
I am trying to automate the login via a website and have come across what I believe is a hidden button.
Using inspect element this all I have to work with.
<button onclick="javascript:ga('send', 'event', 'Sign In','click','Sign In');" type="submit">Sign In</button>
I have tried using getElementById
, getElementsByTagName
, getElementsByName
Etc but I am unfamiliar with hidden items or how to access them. Is there a way cycle through and the ID tags of hidden items?
The URL is: https://www.eurocarparts.com/login?
Any assistance would appreciated.
Upvotes: 1
Views: 878
Reputation: 84465
Here you go using CSS Selector
Requires VBE > Tools > References > Microsoft HTML Object Library and Internet Controls
Option Explicit
Public Sub GetButton()
Dim IE As New InternetExplorerMedium, html As HTMLDocument '<==InternetExplorerMedium rather than InternetExplorer because for some reason I was getting interface unknown without the change
With IE
.Visible = True
.navigate "https://www.eurocarparts.com/login"
While .Busy Or .readyState < 4: DoEvents: Wend
Set html = .document
End With
Dim button As HTMLButtonElement
Set button = html.body.querySelector("body > section > section.container.content-section.cookiebar > section.row.account-container > div.col-xs-12.col-sm-6.col-md-6.account-box.first > div > form > button")
End Sub
If you put in the immediate window the following:
?button.innerhtml
You get:
Sign In
Note: @SIM's excellent abbreviation.
.querySelector("button[onclick*='Sign In']").Click
Upvotes: 1
Reputation: 1815
You loop all the document buttons until you find the one that has type "Submit" and "Sign In" inside:
Set allButtons = YOURIEOBJ.document.getElementsByTagName("button")
Do While i < allButtons.Length
If allButtons(i).Type = "submit" And allButtons(i).innerText = "Sign In" Then
allButtons(i).Click
Exit Do
End If
i = i + 1
Loop
Sometimes innerText doesn't give you the "Sign In". You can use .Text, or .innerHTML, one of them will give you the "Sign In".
Upvotes: 1