c# inject text in to to fields in html page

284 Views Asked by At

Maybe its just me being a little dumb but I can't find a way to input text into the fields on a website using C#, I have tried looking at HTML agility pack and some javascript injection, but can't find a simple or smart way to do this. Let me come with an example.

Here a html snip from a online website:

<fieldset>
<input type="text" autocomplete="off" placeholder="Vejnavn, husnummer, postnummer" id="autocomplete-adgangsadresse2" class="span3 ui-autocomplete-input">
</fieldset>

I would like to inject some text in so the field to make a automatic seach for me.

Any ideas on how to do this?

1

There are 1 best solutions below

0
On

Try this using HTMLAgilityPack:

var doc = web.Load(url);
HtmlNode node = doc.DocumentNode.SelectNodes("//input[@id='autocomplete-adga‌​ngsadresse2']").Firs‌​t(); 
if (node != null) { 
    node.SetAttributeValue("value", "new value"); 
}