VB.NET/GetElementByClass如何将div类点击?

时间:2015-04-01 13:06:48

标签: html vb.net click getelementbyid getelementsbyclassname

</div></div></div><div class="f u" id="m_more_item"><a href="/browse/likes/?id=1026395497374065&amp;start=30&amp;refid=53"><span>Diğerlerini Gör</span></a></div></div></div></div></div></div></div></body></html>

文件

CODE:

Dim h1 As HtmlElementCollection = Nothing
    h1 = W.Document.GetElementsByTagName("div")
    For Each curElement As HtmlElement In h1
        If InStr(curElement.GetAttribute("classname").ToString, "f u") Then

            curElement.InvokeMember("Click")

但代码不起作用HELP ME?

2 个答案:

答案 0 :(得分:0)

关闭我的示例:VB.Net - select a class using GetElementByClass and then click the item programmatically

问题是您尝试单击DIV而不是尝试单击A HREF标记。你会想要这样做。

因为没有&#34;类&#34;或者关于那个元素的任何东西,那么你可以做类似的事情......

Dim h1 As HtmlElementCollection = Nothing
    h1 = W.Document.GetElementsByTagName("div")
    For Each h1Element as HtmlElement in h1
        Dim NameStr As String = h1Element.GetAttribute("href")
        If ((NameStr IsNot Nothing) And (NameStr.Length <> 0)) Then 
            h1Element.InvokeMember("Click")

答案 1 :(得分:0)

Dim theElementCollection As HtmlElementCollection = Nothing

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")

            If Element.GetAttribute("id") = "m_more_item" And Element.OuterHtml.Contains("Diğerlerini Gör") Then
                Element.InvokeMember("click")
            End If

        Next