digiogi
digiogi

Reputation: 270

.Net c# webbrowser fill input without id or classname

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

Answers (2)

Dimitrije Zoroski
Dimitrije Zoroski

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

Calvin Kwok
Calvin Kwok

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

Related Questions