Domanda

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?

È stato utile?

Soluzione

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

So:

if(((Element)txt).GetAttribute("Class") == "chat_input")
{
        ((Element)txt).TextContent = message;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top