1
我想登录到一个网站使用VBA,但我不能得到它点击提交按钮,即使我做了我已经找到推荐的东西。任何帮助将不胜感激。VBA登录失败getElementsByClassName
下面是HTML表单:
<div class="pdForm login">
<div class="pdLoginBox">
<div class="pdLoginBoxInner">
<div class="pdLoginFieldTitle">
<div>Email Address</div>
<div class="register"></div>
</div>
<input type="email" name="email" value="" class="pdInput text" id="pdLogin-email">
<br>
<div class="pdLoginFieldTitle">
<div>Password</div>
<div class="forgot"><a href="http://myaccount.asdf.com/retrievePassword.php" onclick="pdRetrievePasswordCopyEmail(this);"> Forgot your Password?</a></div>
</div>
<input type="password" name="password" value="" class="pdInput text" id="pdLogin-password">
<div class="pdLoginBtn">
<input type="image" src="http://myaccount.asdf.com/skins/standard_custom/butLogin.gif" border="0" vspace="4">
</div>
<div class="pdRegisterBtn">
</div>
</div>
</div>
</div>
这里是VBA,我试图和它的名称和密码罢了,但即使是通过它在运行时错误代码将无法提交。
Sub Login()
Dim lr As Long, a
Set IE = CreateObject("InternetExplorer.Application")
my_url = "http://myaccount.asdf.com/login.php"
With IE
.Visible = True
.Navigate my_url
.Top = 50
.Left = 530
.Height = 1200
.Width = 1200
Do Until Not IE.Busy And IE.READYSTATE = 4
DoEvents
Loop
End With
' Input the userid and password
IE.Document.GetElementById("pdLogin-email").Value = "[email protected]"
IE.Document.GetElementById("pdLogin-password").Value = "xxxxxx"
Set ElementCol = IE.Document.getElementsByClassName("pdLoginBtn")
For Each btnInput In ElementCol
btnInput.Click
Next btnInput
End Sub
任何想法?在此先感谢您的时间。
感谢您的回复。这给了我一个运行时错误:“对象不支持此属性或方法”。 – Southerncentralrain
建议的代码行假定ElementCol被声明为一个元素而不是元素集合。你能让我知道你正在尝试登录的网站地址吗? – sktneer