Webpage automation

浪尽此生 提交于 2019-12-24 15:57:38

问题


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.

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

The issue is occuring where the last element is not being idenified using Id. I'm getting the following error:

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>

The ID which I have used is "Navigation".

IE.document.parentWindow.window.frames(0).document.getElementById("element id")

回答1:


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

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


来源:https://stackoverflow.com/questions/32713538/webpage-automation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!