0

I have this code for a textbox on a website:

<textarea class="chat_input">

    Enter text for chat here

</textarea>

What I am trying to do, is to put text into it. On a different question, a person showed how to click a link that was a class with this code:

foreach (Node el in webKitBrowser1.Document.GetElementsByTagName("a"))
{
    if (((Element) el).GetAttribute("id") == "lnkId")
    {
        string urlString = ((Element) el).Attributes["href"].NodeValue;
        webKitBrowser1.Navigate(urlString);
    }
}

I tried adapting it for this code here:

message = txtMessage.Text;
foreach(Node txt in wb.Document.GetElementsByTagName("textarea"))
{
    if(((Element)txt).GetAttribute("Class") == "chat_input")
    {
        ((Element)txt).SetAttribute("Value", message);
    }
}

When I debugged it, it went though the code 5 times, which is how many textarea's there was. Does anyone know why it does not fill the textbox?

Dozer789
  • 1,980
  • 2
  • 23
  • 43

1 Answers1

1

You need to not use SetAttribute, but set the TextContent property instead.

So:

if(((Element)txt).GetAttribute("Class") == "chat_input")
{
        ((Element)txt).TextContent = message;
}
Wim
  • 11,998
  • 1
  • 34
  • 57
  • `'WebKit.DOM.Element' does not contain a definition for 'InnerText' and no extension method 'InnerText' accepting a first argument of type 'WebKit.DOM.Element' could be found (are you missing a using directive or an assembly reference?) ` – Dozer789 Mar 19 '14 at 15:07
  • Apologies, try TextContent. – Wim Mar 19 '14 at 15:13