Hello , I try to click a button with no ID? vb.net

Joined
Sep 14, 2016
Messages
4
Reaction score
0
Hi hello every one.
I have try multiple times to get it work in different ways but none of the i have try work
This is the button i try to click
Code:
<button type="submit" name="B5" style="height: 20; background-color: #FFFF00; width:20" onclick="submitform(2);"></button>

and this is my code to perform the click
Code:
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        B5 = WebBrowser1.Document.GetElementById("B5")
        CheckButton = WebBrowser1.Document.GetElementById("B5")

        If Not B5 Is Nothing Then
            B5.SetAttribute("value", "B5")
            'skip_button.InnerText = "skip_ad_button" 'Replace testID by the ID you want
            WebBrowser1.Document.GetElementById("B5").InvokeMember("click")
        End If

        If Not CheckButton Is Nothing Then
            'some code here
        End If

        For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
            If element.InnerText = "B5" Then
                element.InvokeMember("click")
                Return
            End If
        Next

    End Sub
 
That button has a name "B5".. use that instead of the ID Get all buttons and check which one of them has name attribute value "B5" and then click on it.
 
That button has a name "B5".. use that instead of the ID Get all buttons and check which one of them has name attribute value "B5" and then click on it.
i am new on vb can you please give me an example.
 
Unfortunately, I don't know VB, but I do know C# (I don't have VS installed on my mac so I can't give you the exact code), but you can do something like this:
Code:
var buttons = webBrowser1.Document.GetElementsByTagName("button");

foreach(var button in buttons)
{
if(button.GetAttribute("name") == "B5")
{
// Do your  stuff here
}
}

I haven't written C# for ages :D So I it may be a bit different, but the idea is the same.
 
Unfortunately, I don't know VB, but I do know C# (I don't have VS installed on my mac so I can't give you the exact code), but you can do something like this:
Code:
var buttons = webBrowser1.Document.GetElementsByTagName("button");

foreach(var button in buttons)
{
if(button.GetAttribute("name") == "B5")
{
// Do your  stuff here
}
}

I haven't written C# for ages :D So I it may be a bit different, but the idea is the same.
Tank you for the great help , i will try to convert the code to vb , tank you for the help :)
 
Back
Top