0

Here's the html code for the page:

<div class="form-group">
    <label for="TextInput"><font color="#7f2b1b">Account</font></label>
    <input name="Username" class="form-control" placeholder="Enter your Account ID." required="" type="text">
</div>

And here's my attempt of doing it in C#:

foreach (HtmlElement o in webBrowser1.Document.GetElementsByTagName("class"))
        {
            HtmlElement yourElement;
            if (o.GetAttribute("name") == "Username")
            {
                yourElement = o;
                yourElement.SetAttribute("value", "FillingText");
                break;
            }

        }
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Noobzilla
  • 97
  • 1
  • 1
  • 6
  • 2
    So, what's your question? – AntiTcb Apr 27 '16 at 17:47
  • @Noobzilla We'd need more info to help you. First off, is this web forms, MVC or what? Second, why can't you just use an ID on the textbox? Third, why are you manipulating the DOM in C#, why not use the technologies Microsoft has supplied, which of course depends on the answer to the first question. – Avrohom Yisroel Apr 27 '16 at 17:49
  • webBrowser1.Document.GetElementsByTagName("class") -> webBrowser1.Document.GetElementsByTagName("INPUT") – Gusman Apr 27 '16 at 17:56
  • There is a good answer here: [Better way to find control in ASP.NET](http://stackoverflow.com/a/4955836/3472827) – Siyavash Hamdi Apr 27 '16 at 18:28

0 Answers0