qckmini6
qckmini6

Reputation: 124

VB.NET How to fill this textbox on a webbrowser

Trying to fill this text box in a webbrowser programmatically.

<div class="chatmsgwrapper"><textarea rows="3" cols="80" class="chatmsg "></textarea></div>

I tried this but it doesn't work at all...

For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("chatmsgwrapper")
        If element.GetAttribute("class") = "chatmsg " Then
            element.SetAttribute("value", TextBox1.Text)
        End If
    Next

Upvotes: 0

Views: 2004

Answers (2)

c4pricorn
c4pricorn

Reputation: 3481

It doesn't work because chatmsgwrapper is class name, not tag name.
You have html tag textarea.
You can get attribute "classname" (not "class"), then set value.
Here is working example tested on VB2010:

For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("textarea")
    If element.GetAttribute("classname") = "chatmsg " Then
            element.SetAttribute("value", TextBox1.Text)
    End If
Next

Upvotes: 2

jradich1234
jradich1234

Reputation: 1425

GetElementsByTagName() won't retrieve an HTML element by class name. Your tag name is textarea.

Try the following...

For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("textarea")
        If element.GetAttribute("class") = "chatmsg " Then
            element.SetAttribute("value", TextBox1.Text)
        End If
    Next

Upvotes: 1

Related Questions