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