使WebBrowser单击VB.net中具有特定类ONCE的网页上的按钮 [英] Make WebBrowser click a button on a webpage with a specific class ONCE in VB.net

查看:303
本文介绍了使WebBrowser单击VB.net中具有特定类ONCE的网页上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让浏览器点击网页中的特定按钮:

I'm trying to make the webbrowser click on a specific button within a webpage:

按钮的html代码类似于 < a class =btn btn-large play> ,我目前为止点击这个按钮的代码是:

The html code for the button is something like <a class="btn btn-large play"> and the code I have so far to click this button is:

For Each Element As HtmlElement In WebBrowser2.Document.GetElementsByTagName("a")
If Element.OuterHtml.Contains("btn btn-large play") Then
Element.InvokeMember("click")
End If

按钮一次又一次。

推荐答案

尝试:

Public count as integer=0

Private Sub WebBrowser_DocumentCompleted(ByVal sender As System.Object,ByVal e As WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted

If count<2 then

For Each Element As HtmlElement In WebBrowser2.Document.GetElementsByTagName("a")
If Element.OuterHtml.Contains("btn btn-large play") Then
Element.InvokeMember("click")
End If

count=count+1
end if

End Sub

这篇关于使WebBrowser单击VB.net中具有特定类ONCE的网页上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆