简体   繁体   English

如何在webkitbrowser中填充文本框?

[英]How do I fill a textbox in webkitbrowser?

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. 当我对其进行调试时,它经过了5次代码,这就是有多少textarea Does anyone know why it does not fill the textbox ? 有谁知道为什么它不填充textbox

You need to not use SetAttribute , but set the TextContent property instead. 您无需使用SetAttribute ,而应设置TextContent属性。

So: 所以:

if(((Element)txt).GetAttribute("Class") == "chat_input")
{
        ((Element)txt).TextContent = message;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM