0

我之前在vb中搜索过如何点击网页上的链接,实际上在这个网站上得到了很好的答案。但现在我试图点击另一个链接,让我发布它的代码,这样更容易理解。(第一次问问题,所以放轻松我哈哈)

<div class="pauseButton" style="display: block;"><a href="#" address="true"></a></div>

这是我的代码(这是潘多拉的顺便说一句,这是我的代码让你登录。)

Public Class fMain

Dim elementCollection As HtmlElementCollection

Private Sub fMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    wb.Navigate("http://www.pandora.com")
End Sub

'buttons

Private Sub bLogin_Click(sender As Object, e As EventArgs) Handles bLogin.Click
    elementCollection = wb.Document.GetElementsByTagName("input")

    For Each ele As HtmlElement In elementCollection
        If ele.GetAttribute("name").Equals("email") Then
            ele.SetAttribute("Value", tbEmail.Text)
        End If

        If ele.GetAttribute("name").Equals("password") Then
            ele.SetAttribute("Value", tbPassword.Text)
        End If

        If ele.GetAttribute("type") = "submit" Then
            ele.InvokeMember("click")
        End If
    Next
End Sub

Private Sub bSignOut_Click(sender As Object, e As EventArgs) Handles bSignOut.Click

End Sub

Private Sub bPlay_Click(sender As Object, e As EventArgs) Handles bPlay.Click
    Dim IsRightElement As Boolean = False

    For Each ele As HtmlElement In wb.Document.Links
        If IsRightElement Then
            ele.InvokeMember("click")
            IsRightElement = False
            Exit For
        End If

        If ele.GetAttribute("class") = "playButton" Then
            IsRightElement = True
        End If
    Next
End Sub

Private Sub bPause_Click(sender As Object, e As EventArgs) Handles bPause.Click

End Sub

Private Sub bFavorite_Click(sender As Object, e As EventArgs) Handles bFavorite.Click

End Sub
End Class

任何帮助将不胜感激,如果我让问题变得混乱,我很抱歉,但我几乎知道如何单击具有特定 href="link.com" 的链接,但在这里,唯一将播放按钮与任何其他按钮区分开来的是它的 href="#" 所以帮助不大。再次感谢先进。(:

编辑:我正在尝试制作潘多拉流媒体,我应该在前面提到过。

4

2 回答 2

0

如果您使用的是 Visual Studio.NET,请执行以下操作: 1. 放置一个 HyperLink 控件 2. 在 NavigateUrl 属性下,单击省略号。您现在应该会看到一个包含项目中所有文件的屏幕 3. 选择您的 HTML 文件。如果它不属于您的项目,请使用浏览添加它。

于 2013-03-08T00:01:14.973 回答
0

在 HTML 中,我给链接一个 ID:

<div class="pauseButton" style="display: block;"><a id="LinkID" href="#" address="true"></a></div>

VB.Net 代码通过 Id 获取元素并调用它:

Private Function ClickSubmitButton()

        Dim theButton As HtmlElement

        Try

            ' Link the ID from the web form to the Button var
            theButton = webbrowser1.Document.GetElementById("LinkID")

            ' Now do the actual click.
            theButton.InvokeMember("click")
            Return True

        Catch ex As Exception

            Return False

        End Try

    End Function

更新:

好的,如果没有 LinkID,您需要遍历所有元素,一旦确定了 DIV,您就知道下一个元素是链接...

Dim IsRightElement as Boolean = False
For Each ele As HtmlElement In wb.Document.Links
        If IsRightElement Then
           ele.InvokeMember("click")
           IsRightElement = False
           Exit For
        End If
        If ele.GetAttribute("class") = "playButton" Then
            IsRightElement = True
        End If
    Next
于 2013-03-08T00:12:57.643 回答