我正在尝试自动登录网站,每次我都这样做,我会得到"方法'文档'对象' IWebBrowser2'失败"错误。该网站是内联网,很可能无法访问,但是,我将提供我正在查看的代码。
它使用java和html,名称相同,ID名称相同。我尝试过使用确切的名称,并且我也尝试过使用通配符,它仍然给我上述错误。我也尝试过使用NAME和ID,但似乎对我都不起作用。
HTML Code
<TD class=style6><SPAN style="FONT-SIZE: 9pt" id=ContentPlaceHolder1_Label1 class=style1>VZID:</SPAN>
<BR><INPUT style="WIDTH: 125px" id=ContentPlaceHolder1_userid class=text name=ctl00$ContentPlaceHolder1$userid>
<BR><SPAN style="FONT-SIZE: 9pt" id=ContentPlaceHolder1_Label2 class=style1>Password:</SPAN>
<BR><INPUT style="WIDTH: 125px" id=ContentPlaceHolder1_password class=text name=ctl00$ContentPlaceHolder1$password value="" type=password>
<BR><BR><INPUT id=ContentPlaceHolder1_submitthis class=button name=ctl00$ContentPlaceHolder1$submitthis value=Login type=submit> </TD>
这是脚本:
<span id="ContentPlaceHolder1_Label1" class="style1" style="font-size:9pt;">VZID:</span>
<br />
<input name="ctl00$ContentPlaceHolder1$userid" type="text" id="ContentPlaceHolder1_userid" class="text" style="width:125px;" />
<br />
<span id="ContentPlaceHolder1_Label2" class="style1" style="font-size:9pt;">Password:</span>
<br />
<input name="ctl00$ContentPlaceHolder1$password" type="password" id="ContentPlaceHolder1_password" class="text" style="width:125px;" />
<br />
<br />
<input type="submit" name="ctl00$ContentPlaceHolder1$submitthis" value="Login" id="ContentPlaceHolder1_submitthis" class="button" />
</td>
<td>
最后,这是我在VBA工作的代码,这是我最后一次尝试使用它的代码:
Sub sbIE_OpenVMOSite()
uname = "username"
pword = "password"
fdUSERNAME = "*usename*"
fdPASSWORD = "*password*"
fdSUBMIT = "*submitthis*"
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "Thewebsite"
Dim IE As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' Send the form data To URL As POST binary request
IE.Navigate "http://ccssid.verizon.com/login.aspx"
' Wait while loading...
Do While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Loop
IE.Visible = True
'Release Set
'IE = Nothing
'On Error Resume Next
IE.document.getElementById(fdUSERNAME).Value = uname 'Enters Username
IE.document.getElementById(fdPASSWORD).Value = pword 'Enters Password
IE.document.all(fdSUBMIT).Click
End Sub
感谢您的帮助
**编辑**
所以我尝试修改延迟而不是我得到一个不知道错误的界面...
Sub sbIE_OpenVMOSite()
uname = "username"
pword = "password"
myWebsite = "TheWebsite"
fdUSERNAME = "ContentPlaceHolder1_userid"
fdPASSWORD = "ContentPlaceHolder1_password"
fdSUBMIT = "ContentPlaceHolder1_submitthis"
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate myWebsite
IE.Visible = True
'Application.Wait DateAdd("s", 5, Now)
'Do While IE.Busy
' Application.Wait DateAdd("s", 5, Now)
'Loop
'Wend
Do
If IE.readyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop
'MsgBox ("POP")
IE.document.getElementByID(fdUSERNAME).Value = uname 'Enters Username
IE.document.getElementByID(fdPASSWORD).Value = pword 'Enters Password
IE.document.all(fdSUBMIT).Click
End Sub
答案 0 :(得分:1)
试试这个!我纠正了fdUSERNAME(以及fdPASSWORD和fdSUBMIT,当我在它时,但它们可能没有像他们那样引起任何问题)。另外,我稍微清理了一下代码。
Sub sbIE_OpenVMOSite()
uname = "username"
pword = "password"
myWebsite = "http://TheWebsite"
fdUSERNAME = "ContentPlaceHolder1_userid"
fdPASSWORD = "ContentPlaceHolder1_password"
fdSUBMIT = "ContentPlaceHolder1_submitthis"
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate myWebsite
IE.Visible = True
While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Wend
IE.document.getElementById(fdUSERNAME).Value = uname 'Enters Username
IE.document.getElementById(fdPASSWORD).Value = pword 'Enters Password
IE.document.all(fdSUBMIT).Click
End Sub