在WebBrowser控件(C#/ .NET)中设置TextArea的值

2 .net html c# webbrowser-control

我想使用.NET WebBrowser控件设置TextArea的值.

我已经能够使用以下代码设置文本框的值(将"username"替换为texbox的名称):

webBrowser1.Document.All.GetElementsByName("username")[0].SetAttribute("Value", "SomeUser");
Run Code Online (Sandbox Code Playgroud)

我尝试在TextArea上使用类似的代码(使用GetElementById)并且无法记住TextArea输入类型不包含"Value"属性.我还尝试设置TextArea的InnerHtml和InnerText,但在尝试设置TextArea输入的值时,编译器继续抛出空引用异常错误或索引超出范围错误.

有没有人知道如何使用WebBrowser控件在TextArea中设置文本?任何建议将不胜感激!

Dan*_*ant 7

假设您有以下HTML:

<html>
<body>
   <textarea id='foo'>Testing</textarea>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

您可以textarea像这样设置文本:

HtmlElement textArea = webBrowser1.Document.All["foo"];
if (textArea != null)
{
    textArea.InnerText = "This is a test";
}
Run Code Online (Sandbox Code Playgroud)