使用VBScript单击链接

时间:2018-10-11 17:39:15

标签: internet-explorer vbscript hyperlink

我尝试自动执行网页上的某些处理。我已经阅读了所有可以找到的文章,但是不合适。

这是部分网页:

Webpage with data to retrieve

下面是HTML:

<div class="rgWrap rgArrPart2">
<a title="Go to Next Page" href="javascript:__doPostBack('ctl00j','')">Volgende</a>
<input type="submit" name="ctl003" value=" " title="Next Page" class="rgPageNext" /> 
<a title="Go to Last Page" href="javascript:__doPostBack('ctl004','')">Laatste</a>
<input type="submit" name="ctl005" value=" " title="Last Page" class="rgPageLast" />

“ Volgende”和“ Laatste”是荷兰语,表示“下一个”和“最后一个”。

我尝试构建的代码需要单击“ Volgende”,这样我才能获得包含记录的下一页。

我尝试了以下代码:

  • GetElementById()

    IE.Document.GetElementById("ctl00j").Click()
    
  • GetElementsByTagName()并按值过滤:

    Set oInputs = IE.Document.GetElementsByTagName("input")
    For Each elm In oInputs
        If elm.Value = "Go to Next Page" Then
            elm.Click
            Exit For
        End If
    Next
    
  • GetElementsByClassName()

    For Each elem In IE.Document.GetElementsByClassName("rgPageNext")
        If elem.innerText = "Go to Next Page" Then
            elem.Focus
            elem.Click
        End If
    Next
    
  • GetElementsByTagName()并按class属性进行过滤:

    For Each a In IE.document.getElementsByTagName("a")
        If a.GetAttribute("class") = "rgPageNext" Then
            a.Click
            Exit For
        End If
    Next
    
  • GetElementsByTagName()并按title属性进行过滤:

    For Each a In IE.document.getElementsByTagName("a")
      If a.getAttribute("title") = "Go to Next Page" Then
        a.Click
        Exit For
      End If
    Next
    

第一种方法给出此错误消息:

  

脚本:K:\ temp \ TT \ mftt.vbs
  线:37
  字符:2
  错误:所需对象:'IE.Document.getElementByID(...)'
  代号:800A01A8
  来源:Microsoft VBScript运行时错误

其他尝试均未给出错误消息,但对单击链接也没有任何反应。我在这里OnClick事件中丢失了。与该项目中的其他链接一起,出现了OnClick事件。我无法更改HTML,所以卡住了。

UPDATE1:到目前为止添加了代码。我只忙于单击链接。我没有构建任何流程或迭代。接下来将要介绍。

    ' // Login procedure for ... //
Dim WshShell
Dim IE
Dim strLoginName
Dim strPassword

Set WshShell = WScript.CreateObject("WScript.Shell")
SET IE = Nothing

Call LogIn

Function LogIn
    Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
    IE.Visible = True
    IE.Navigate "https://www.mijn.nl/"
    Wait IE,500
    With IE.Document
        .getElementByID("ctl00_mainContentPlaceHolder_ctl00_Login1_UserName").value = "username"
        .getElementByID("ctl00_mainContentPlaceHolder_ctl00_Login1_Password").value = "password"
        .getElementByID("ctl00_mainContentPlaceHolder_ctl00_Login1_LoginButton1").Click()
    End With
    Wait IE, 500
    IE.Navigate "https://www.mijn.nl/deelnemerlijst.aspx"
    'now we have the page where we can select the clients
    Wait IE, 500
    With IE.Document
        'by clicking the 'search' button, we create a client list 
        .getElementByID("ctl00_mainContentPlaceHolder_ctl00_zoekLanguageButton").Click()
        Wait IE, 500
        'in the client list we select the first one
        'here I need to make a iteration for all the clients
        .getElementById("ctl00_mainContentPlaceHolder_ctl00_RadGrid1_ctl00_ctl04_DeelnemerKodeLinkButton").Click()
        Wait IE, 500
    End With
    'We go to the transction overview page
    IE.navigate "https://www.mijn.nl/Overzichten/TransactionOverview.aspx"
    Wait IE, 1500
    'here I need to click on ">" on the page to open details I need to extract
    'There are max 10 lines
    ' [ some iteration code ] 
    'click on next transaction page
    For Each a In IE.document.getElementsByTagName("a")
        If a.getAttribute("title") = "Go to Next Page" Then
        a.Click
        Exit For
      End If
    Next
End Function

Sub Wait(IE, SleepInterval)
    Do
        WScript.Sleep SleepInterval
    Loop While IE.ReadyState < 4 Or IE.Busy
End Sub

SET IE = Nothing

0 个答案:

没有答案