网页自动化 [英] Webpage automation
问题描述
我正在尝试使用 VBScript 在网页上自动获取屏幕截图.我被困在 VBScript 无法识别我需要单击的元素的地方.
I am trying to auto-fetch a screenshot on webpage using VBScript. I am stuck at a point where the VBScript is not able to identify an element which I need to click.
有什么方法可以识别其他 elementId 元素,例如 xpath/title/value/name
,这些元素在 Selenium 网页自动化中更容易识别.这是我的脚本:
Is there any way to identify the element other elementId like xpath/title/value/name
which are much more easily identified in Selenium webpage automation. Here is my script:
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 识别最后一个元素的情况.我收到以下错误:
The issue is occuring where the last element is not being idenified using Id. I'm getting the following error:
错误:需要对象:'document.getElementById(...)'
代码:800A01A8
Error : Object required :'document.getElementById(...)'
Code : 800A01A8
这是我在这里使用的演示.页面上的框架编码为:
That's the demo I have used here. The frame coding on the page is :
<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 是导航".
The ID which I have used is "Navigation".
IE.document.parentWindow.window.frames(0).document.getElementById("element id")
推荐答案
看起来您的 IE
句柄与实际 IE 实例断开连接.尝试重新附加它:
Looks like your IE
handle got disconnected from the actual IE instance. Try re-attaching it:
...
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 Explorer 窗口,您可以使用窗口标题而不是可执行文件名称来选择正确的一个:
If you have more than one Internet Explorer window you could use the window title instead of the executable name to select the correct one:
For Each wnd In app.Windows
If InStr(1, wnd.LocationName, "page title", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
这篇关于网页自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!