我正在尝试使用VBScript自动获取网页上的截图。我被困在一个VBScript无法识别我需要单击的元素的地方。
是否有任何方法可以识别其他elementId (如xpath/title/value/name )元素,这些元素在Selenium网页自动化中更容易识别。这是我的剧本:
Dim IE
Dim Helem
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate "https://mylink/logon.jsp"
Do While (IE.Busy)
WScript.Sleep 3
Loop
Set Helem = IE.document.getElementByID("overridelink")
Helem.Click
Do While (IE.Busy)
WScript.Sleep 3
Loop
Set Helem = IE.document.getElementById("j_username")
Helem.Value = "user123"
Set Helem = IE.document.getElementById("j_password")
Helem.Value = "pass123"
IE.document.getElementById("other").Click
Do While (IE.Busy)
WScript.Sleep 10
Loop
IE.document.getElementById("elementId").Click当最后一个元素没有使用Id进行标识时,就会出现这个问题。我得到了以下错误:
错误:对象必需:‘document.getElementById(.)’ 编号: 800A01A8
这就是我在这里用过的演示。页面上的帧编码是:
<frameset id="Cmain" ////<br/>
<FRAME id="Banner" //<br/>
<frameset id="content" //<br/>
<FRAME id="Navigation" //<br/>
<frameset rows=//<br/>
<FRAME id="Taskbar" //<br/>
<FRAME id="Work" //<br/>
<FRAME id="Work_NonSM" //<br/>
</frameset><br/>
</frameset>
</frameset>我使用的ID是“导航”。
IE.document.parentWindow.window.frames(0).document.getElementById("element id")发布于 2015-09-22 11:35:35
看起来您的IE句柄与实际的IE实例断开了连接。试着重新连接它:
...
Set app = CreateObject("Shell.Application")
For Each wnd In app.Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
IE.document.getElementById("elementId").Click如果有多个Internet窗口,则可以使用窗口标题而不是可执行文件名来选择正确的名称:
For Each wnd In app.Windows
If InStr(1, wnd.LocationName, "page title", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Nexthttps://stackoverflow.com/questions/32713538
复制相似问题