Make WebBrowser click a button on a webpage with a specific class ONCE in VB.net

questions :


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

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

This works, but it makes the Webbrowser click the button again and again. Any idea how I can only make it do so twice?

 

 

————————————————-

Answer :

maybe simply like this? 🙂

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

 

 

 

click,getelementsbytagname,html,vb.net,webbrowser-control

Facebook Comments

Post a comment