Reputation: 270
I need to fill an input in webbrowser but this doesn't work. I think it has to be done with name property but how?
foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input"))
{
if (login.GetAttribute("name") == "username")
{
login.SetAttribute("value", "xyz");
}
}
For this data:
<input class="lfFieldInput" type="text" name="username" maxlength="30"
autocapitalize="false" autocorrect="false" value="" data-reactid=".0.0.0.1">
But code is not filling the data (xyz).
Upvotes: 0
Views: 362
Reputation: 351
Maybe this work
HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement element in col)
{
if (element.GetAttribute("name").Equals("username"))
{
element.SetAttribute("value", "xyz");
}
}
Upvotes: 1
Reputation: 161
Have you tried the following way:
IHTMLElementCollection inputElements = webBrowser1.Document.GetElementsByTagName("input")
foreach (HtmlElement login in inputElements)
{
if (login.GetAttribute("name") == "username")
{
login.SetAttribute("value", "xyz");
}
}
Upvotes: 1