Gettig Htmlelement based on HtmlAgilityPack.HtmlNode

Topics: Developer Forum, User Forum
Sep 6, 2012 at 7:39 AM

I am able to find Html Node using following code in HtmlAgility Document.

But after getting the HtmlNode, I want to retun the corresponding System.Windows.Forms.Htmlelement(Webbrowser).

Please help me if any one has done this before.

 
HtmlAgilityPack.HtmlDocument htmlAgility = new HtmlAgilityPack.HtmlDocument();
htmlAgility.LoadHtml(WebBrowser.DocumentText);
string xPath= "/html[1]/body[1]/table[1]/tr[1]/td[1]/table[1]/tr[1]/td[1]/div[1]/table[1]/tr[3]/td[3]/input[1]";
HtmlAgilityPack.HtmlNode retrunElement;


IEnumerable<HtmlAgilityPack.HtmlNode> HAPnodes = Enumerable.Empty<HtmlAgilityPack.HtmlNode>();
                HtmlAgilityPack.HtmlNode node = htmlAgility.DocumentNode;
                HAPnodes = node.SelectNodes(xPath);

if (HAPnodes.Count() == 1)
                {
                    retrunElement = HAPnodes.ElementAt(0);
}