我想使用VBScript单击在Internet Explorer中运行的应用程序的GUI中显示“添加文档”的按钮。问题是源代码中没有“id”,“name”或“class”元素(见下文)用作脚本中的引用。
Source Code:
<TD>
<INPUT type="button" value="Add Document" onclick="addFileUploadBox()">
</TD>
我的代码如下所示,适用于具有源代码ID的元素。还包括一些失败的尝试根据我的谷歌搜索点击有问题的按钮,但我无法开始工作。我是新手,任何帮助都会受到赞赏 - 有什么建议可以解决吗?
My Code:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://sharemxxxx.xxxxx.com/xxxImport/import.aspx"
While objIE.Busy
WScript.Sleep 100
Wend
objIE.Document.getElementById("txtReferenceNum").value = "15226002"
objIE.Document.getElementById("ddlCategory").value = "05"
objIE.Document.getElementById("btnRetrieve").click
' ABOVE CODE WORKS
' NOT WORKING #1 - DOES NOTHING - NO ERROR
'===========================================
objIE.Document.getElementByType("btn").Value="Add Document"
For Each btn In objIE.Document.getElementsByTagName("input")
If btn.Value="Add Document"Then btn.Click()
Next
' NOT WORKING #2 - DOES NOTHING - NO ERROR
'===========================================
For Each Button In objIE.Document.getElementsByTagName("input")
If Button.Value="Add Document"Then Button.Click()
Next
' NOT WORKING #3 - DOES NOTHING - NO ERROR
'===========================================
Set oInputs = objIE.Document.getElementsByTagName("input")
For Each elm In oInputs
If elm.Value = "Add Document" Then
elm.Click
Exit For
End If
Next
' NOT WORKING #4 - Show Empty Msg Box
'===========================================
set objButtons = objIE.document.getElementsByTagName("input")
for each objButton in objButtons
strText = objButton.innerhtml
msgbox strText
if (strText = "Add Document") then
msgbox "found the button!"
objButton.click
exit for
end if
next
答案 0 :(得分:0)
您可能甚至不需要找到该元素。看起来按钮只是调用JavaScript函数。因此,您可以使用execScript()
函数来运行它。
例如:
objIE.Document.parentWindow.execScript "addFileUploadBox();", "javascript"