如何点击没有ID的按钮

时间:2013-05-13 01:45:50

标签: vb.net getelementbyid

我正在使用VB.Net而且我正在使用 WebBrowser1.Document.GetElementById("submit").InvokeMember("click")

但我似乎找不到实际的ID。我正在尝试从网站上找到登录按钮ID:http://grooveshark.com/#!/login

任何解决方案?

2 个答案:

答案 0 :(得分:0)

你可以得到这样的所有按钮

WebBrowser1.Document.GetElementsByTagName("button")

提交表单可能更容易。

Dim form As HtmlElement = WebBrowser1.Document.GetElementById("formId")

If form IsNot Nothing Then
        form.InvokeMember("submit")
End If

答案 1 :(得分:0)

试试这个:

Public Sub ClickSearching(ByVal targetType As String, ByVal targetText As String)
    Dim bFounded As Boolean = False
    Dim tags As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName(targetType)

    For Each elem As HtmlElement In tags
        Application.DoEvents()

        If elem.GetAttribute("value") = targetText Then
            elem.InvokeMember("click")
            bFounded = True
            Exit For
        End If
    Next

    If Not bFounded Then
        Throw New Exception("No se encontró ningún resultado para la función ClickSearching(" & targetType & "," & targetText & ")")
    End If
End Sub