GettingStarted
GettingStarted

Reputation: 7605

How can I click a link in an HtmlNode

I am creating a headless C# application and one of my HTML elements looks like

<input name="SUBMIT-chn.pss" title="Select" class="image  selectIcon" type="image" alt="Select" src="docs/pics/select.png">

My method looks like

    private void AddInputElement(HtmlNode element)
    {
        string name = element.GetAttributeValue("name", "");
        string value = element.GetAttributeValue("value", "");
        string type = element.GetAttributeValue("type", "");

        if (string.IsNullOrEmpty(name)) return;

        switch (type.ToLower())
        {                
            case "image":
                'I would like to do something like element.Click to go to the next page.
            default:
                Add(name, value);
                break;
        }
    }

I am using HtmlAgilityPack 1.4.9 with .Net 4.5.2

Thank you

Upvotes: 0

Views: 1234

Answers (1)

har07
har07

Reputation: 89285

HtmlAgilityPack (HAP) is the wrong tool for this kind of task. It is only a HTML parser, which enable you to extract information from the source HTML, modify a bit of the HTML, and so on. HAP works on HTML markup level, and you can't interact with the HTML controls through HAP.

To click on a link, type on a textbox and so on, you need a real browser or something that emulate a real browser. You might want to look into .NET binding of Selenium WebDriver using PhantomJS headless browser to accomplish this. See a simple example here.

Upvotes: 1

Related Questions