Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[VB.Net] perform click for a class button

Joined
Apr 13, 2012
Messages
536
Reaction score
32
Hello , i want to perform click to a button class but i couldnt here is my code
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
If element.GetAttribute("class") = "testclassbutton" Then
element.InvokeMember("click")
End If
Next
Any idea ?
or how can i send enter press to WebBrowser1 control programmatically ? , i tried sendkeys function but couldnt do it , thanks
 
Joined
Aug 16, 2006
Messages
1,251
Reaction score
199
You're on the right track.
you are missing your exit for.
Other than that, the only thing i can think of is if the attribute or tag name is incorrect.

Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click    
Dim elements = WebBrowser1.Document.GetElementsByTagName("input")   ' or whatever tag it is
    For Each element As HtmlElement In elements
        ' test here if this is the element of your interest.
        ' e.g.
        If element.GetAttribute("className") = "someclass" Then
            element.InvokeMember("click")   ' if found, click it!
            Exit For
        End If
    Next
End Sub
 
Joined
Apr 13, 2012
Messages
536
Reaction score
32
You're on the right track.
you are missing your exit for.
Other than that, the only thing i can think of is if the attribute or tag name is incorrect.

Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click    
Dim elements = WebBrowser1.Document.GetElementsByTagName("input")   ' or whatever tag it is
    For Each element As HtmlElement In elements
        ' test here if this is the element of your interest.
        ' e.g.
        If element.GetAttribute("className") = "someclass" Then
            element.InvokeMember("click")   ' if found, click it!
            Exit For
        End If
    Next
End Sub

For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
If element.GetAttribute("class") = "testclassbutton" Then
element.InvokeMember("click")
Exit For
End If
Next
it made a cyan frame around the button that i wanna perform a click to any idea ?
 
Back
Top