IE 自动化 VBA - 隐藏按钮



我正在尝试通过网站自动登录,并遇到了我认为是隐藏按钮的东西。

使用检查元素,这就是我必须使用的全部内容。

<button onclick="javascript:ga('send', 'event', 'Sign In','click','Sign In');" type="submit">Sign In</button>

我尝试使用getElementByIdgetElementsByTagNamegetElementsByName等,但我不熟悉隐藏项目或如何访问它们。有没有办法循环和隐藏物品的 ID 标签?

网址为: https://www.eurocarparts.com/login?

任何协助将不胜感激。

循环所有文档按钮,直到找到里面有"提交"和"登录"类型的按钮:

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

有时 innerText 不会为您提供"登录"。您可以使用 .文本或.innerHTML,其中一个将为您提供"登录"。

在这里使用CSS选择器

需要 VBE>工具> HTML 对象库和互联网控件> Microsoft引用

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

如果在即时窗口中输入以下内容:

?button.innerhtml

你会得到:

Sign In

注意:@SIM的缩写很好。

.querySelector("button[onclick*='Sign In']").Click

最新更新