I constantly had problems with the Html Agility Pack; my XPath queries only work when they are very simple:
//*[@id='some_id']
or
However, at any time when they become more complex, the Html Agility Pack cannot handle this. Here is an example that demonstrates the problem: I use WebDriver to go to Google and return the source of the page that is passed to the Html Agility Pack, and both WebDriver and HtmlAgilityPack try to find the / node element (C #):
const string xpath = "//form//tr[1]/td[1]//input[@name='q']";
var driver = new FirefoxDriver(new FirefoxProfile()) { Url = "http://www.google.com" };
Thread.Sleep(2000);
var e = driver.FindElementByXPath(xpath);
Console.WriteLine(e!=null ? "Webdriver success" : "Webdriver failure");
var source = driver.PageSource;
var htmlDoc = new HtmlDocument { OptionFixNestedTags = true };
htmlDoc.LoadHtml(source);
var nodes = htmlDoc.DocumentNode.SelectNodes(xpath);
Console.WriteLine(nodes!=null ? "Html Agility Pack success" : "Html Agility Pack failure");
driver.Quit();
In this case, WebDriver successfully placed the item, but the Html Agility Pack did not.
, , xpath , : //input [@name= 'q'], , , -, , , xpath WebDriver FirePath FireFinder Firefox.
WebDriver , Html Agility Pack ?