Reputation: 161
I'm trying to fill a form field in a WebBrowser control using HtmlElement.InnerText. The field is pre-filled with some greyed out placeholder text "Search your purchases", but when I fill the field with my own text it's also greyed out and has no effect when I click the submit button.
If I type the text into the field manually instead it's black and works allright when I click submit.
How do I get this to work? Here's the form html:
<form role="form" action="/mod/bcs/account/" method="get" class="margin-top-20">
<div class="input-group">
<input class="form-control" name="searchPurchases" type="text" placeholder="Search your purchases" value="" id="search-bcs">
<div class="input-group-btn">
<button type="submit" class="btn btn-success">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</form>
My own code:
HtmlElement searchBox = webBrowser.Document.GetElementById("search-bcs");
searchBox.InnerText = "text";
Upvotes: 1
Views: 2433
Reputation: 7880
As stated by my comments, the value contained by an <input>
element is held in the value
attribute, and not in a child text node.
If you want to change the value through code, you need to use HtmlElement.SetAttribute() as follows:
searchBox.SetAttribute("value", "text");
Upvotes: 2