使用VBA(getElementsByClassName)在Internet Explorer中单击一个按钮 [英] Clicking a button in Internet Explorer using VBA (getElementsByClassName)
本文介绍了使用VBA(getElementsByClassName)在Internet Explorer中单击一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用VBA和HTML在Internet Explorer窗口中单击一个按钮.该按钮没有"id",因此我必须通过"classname"来找到它.
I'm trying to click a button within an Internet Explorer window using VBA and HTML. The button has no "id" so I have to locate it by "classname."
按钮的HTML代码如下:
The button's HTML code is as follows:
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only`"
VBA代码:
Private Sub CommandButton21_Click()
Const cURL = "xxxxxx.com"
Const cUsername = "xxxxxx"
Const cPassword = "xxxxxx"
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim CVBATButton As HTMLInputButtonElement
Set IE = New InternetExplorer
IE.Visible = True
IE.navigate cURL
Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Set doc = IE.document
'A previous login window that leads me into a new window, where I need to click a button.
Set LoginForm = doc.forms(0)
Set UserNameInputBox = doc.getElementById("BIA_Login")
UserNameInputBox.Value = cUsername
Set PasswordInputBox = doc.getElementById("BIA_Pass")
PasswordInputBox.Value = cPassword
Set SignInButton = doc.getElementById("login")
SignInButton.Click
'It's this portion of the code below that I'm struggling with
Set doc = IE.document
Set LoginForm = doc.forms(0)
Application.Wait Now + TimeValue("00:00:03")
Set CVBATButton = doc.getElementsByClassName("ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only")
CVBATButton.Click
推荐答案
我遇到了相同的错误, 试试这个(对我有用):
I had the same Error, try this (it worked for me):
Set CVBATButton = doc.getElementsByClassName("ui-button ui-widget ui-state-
default ui-corner-all ui-button-text-only")
For Each btn In CVBATButton
btn.Click
Exit For
Next
这篇关于使用VBA(getElementsByClassName)在Internet Explorer中单击一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文