Internet explorer 使用VBscript 0x80010108自动化IE-未知异常
我正在尝试使用VBScript单击网页上的按钮。我的脚本的其余部分工作得很好。但是在使用browser对象的不同实例中,我得到了一个例外。相同的代码适用于不同网站的另一个脚本 这是我的密码:Internet explorer 使用VBscript 0x80010108自动化IE-未知异常,internet-explorer,exception,vbscript,Internet Explorer,Exception,Vbscript,我正在尝试使用VBScript单击网页上的按钮。我的脚本的其余部分工作得很好。但是在使用browser对象的不同实例中,我得到了一个例外。相同的代码适用于不同网站的另一个脚本 这是我的密码: Set browser = OpenBrowser(strURL) If Not (browser.document.GetElementByID("ctl00$ContentPlaceHolder1$btnSubmit") Is Nothing) Then browser.document
Set browser = OpenBrowser(strURL)
If Not (browser.document.GetElementByID("ctl00$ContentPlaceHolder1$btnSubmit") Is Nothing) Then
browser.document.GetElementByID("ctl00$ContentPlaceHolder1$btnSubmit").Click
Else
MsgBox "Submit button Click failed"
Wscript.Quit
End If
Function OpenBrowser(URL)
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate2 URL
WaitForBrowserReadyStatus(ie)
Set OpenBrowser = ie
End Function
Private Sub WaitForBrowserReadyStatus(ie)
Const WAIT_TIMEOUT = 2000
While (ie.Busy) or (ie.ReadyState <> 4)
WScript.Sleep(WAIT_TIMEOUT)
' wait (1)
Wend
End Sub
或浏览:
While (ie.Busy) or (ie.ReadyState <> 4)
While(即忙)或(即ReadyState 4)
这段代码适用于另一个不同网站的VBScript,因此我不知道它为什么会抛出这些异常。GetElementByID()
可能会很棘手。如果找到元素,一切正常,您可以将对象引用指定给变量。但是如果找不到元素,VBScript在尝试执行对象分配或对象比较时将抛出一个“Object Required”
错误(例如,为Nothing
)
诀窍是使用IsObject()
测试返回的值是否确实是对象。如果是,请执行对象指定或按正常方式执行其他操作
If IsObject(browser.Document.getElementByID("ctl00$ContentPlaceHolder1$btnSubmit")) Then
' Object returned. ID was found in the DOM. Safe to assign.
Dim e
Set e = browser.Document.getElementByID("ctl00$ContentPlaceHolder1$btnSubmit")
e.Click
Else
' Not an object. In other words, the ID wasn't found in the DOM.
End If
GetElementByID()
可能很棘手。如果找到元素,一切正常,您可以将对象引用指定给变量。但是如果找不到元素,VBScript在尝试执行对象分配或对象比较时将抛出一个“Object Required”
错误(例如,为Nothing
)
诀窍是使用IsObject()
测试返回的值是否确实是对象。如果是,请执行对象指定或按正常方式执行其他操作
If IsObject(browser.Document.getElementByID("ctl00$ContentPlaceHolder1$btnSubmit")) Then
' Object returned. ID was found in the DOM. Safe to assign.
Dim e
Set e = browser.Document.getElementByID("ctl00$ContentPlaceHolder1$btnSubmit")
e.Click
Else
' Not an object. In other words, the ID wasn't found in the DOM.
End If
我试过了,但是在If语句中出现了一个0x800706b5-未知异常。好的,我最初发布的代码适用于其他网站,但不适用于我需要的网页。这是因为我尝试使用的网页是一个内部网页表单吗?我尝试了这个,但我在If语句中得到一个0x800706b5-未知异常。好的,我最初发布的代码适用于其他网站,但不是我需要的网页。是因为我尝试使用的网页是一个内部网络表单吗?