Hello Community,
I want to know if there is a way to make a program that will click a button on a webbrowser but the button does not have a name (name="") or id (id="") property it just has a class (class="") property and if there is a way is there also a way to place text in a textbox on the webbrowser again the textbox does not have a name (name="") or id (id="") property it just has a class (class="") property.

Dani AI

Generated

Contrary to , you can target elements that only have a class from VB.NET's WebBrowser — the DOM exposes attributes and you can either filter elements in .NET or run a small JavaScript selector. Two reliable approaches follow: iterate elements returned by GetElementsByTagName and test the element's class, or call CSS selectors (querySelector/querySelectorAll) via InvokeScript and act on the matched node(s).

' Example: find a button/input by class and click/set value (run after DocumentCompleted)
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim doc = WebBrowser1.Document
    If doc Is Nothing Then Return

    ' buttons (also check "a" or "div" if the page uses them as buttons)
    For Each el As HtmlElement In doc.GetElementsByTagName("button")
        Dim cls = el.GetAttribute("className")
        If String.IsNullOrEmpty(cls) Then cls = el.GetAttribute("class")
        If Not String.IsNullOrEmpty(cls) AndAlso cls.Split(" "c).Contains("myButtonClass") Then
            el.InvokeMember("click")
            Exit For
        End If
    Next

    ' inputs
    For Each inp As HtmlElement In doc.GetElementsByTagName("input")
        Dim cls = inp.GetAttribute("className")
        If Not String.IsNullOrEmpty(cls) AndAlso cls.Split(" "c).Contains("myInputClass") Then
            inp.SetAttribute("value", "text to enter")
            Exit For
        End If
    Next
End Sub

If the page supports modern selectors, using querySelector from VB is shorter:

Dim script As String = "var b=document.querySelector('button.myButtonClass'); if(b) b.click();" &
                       "var i=document.querySelector('input.myInputClass'); if(i) i.value='hello';"
WebBrowser1.Document.InvokeScript("eval", New Object() {script})

Troubleshooting notes: run this after DocumentCompleted (some pages load UI later via AJAX), watch for frames/iframes (use Document.Window.Frames(index).Document), remember class attributes can contain multiple classes so match carefully, and the WinForms WebBrowser is IE-based — very old IE builds may lack querySelector; fall back to the GetElementsByTagName method when needed. If automation still fails, inspect the element with F12 DevTools to confirm tag, class, and whether the element is inside shadow DOM or injected later.

Hi
I'd say no, a browser only uses the class for CSS formating it can not identify a certain entity by anything other than it's ID field in Javascript and Name when the form is submitted

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.