2 HtmlElement命令中的webbrowser

时间:2015-02-27 05:37:30

标签: html vb.net

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    Dim elements As HtmlElementCollection = WebBrowser1 And WebBrowser2.Document.All

    For Each webpageelement As HtmlElement In elements

        If webpageelement.GetAttribute("id") = "skip_ad_button" Then

            webpageelement.InvokeMember("click")


        End If
    Next

End Sub

我想将2个webbrowser放在同一个timer3中![在此处输入图片说明] [1]

图片:[http://i.stack.imgur.com/YVnG2.jpg][1]

1 个答案:

答案 0 :(得分:1)

如果您创建HtmlElementCollection数组,则可以使用此代码同时控制多个文档:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim elements As HtmlElementCollection() = New HtmlElementCollection() {WebBrowser1.Document.All, WebBrowser2.Document.All}

    For Each webpageelementcollection As HtmlElementCollection In elements
        For Each webpageelement As HtmlElement In webpageelementcollection
            If webpageelement.GetAttribute("id") = "ELEMENT_ID" Then
                webpageelement.InvokeMember("click")
            End If
        Next
    Next
End Sub