Html Agility Pack cannot find list parameter using xpath

This is related to my previous question , but it seems that I have another case where the Html Agility Pack does not work as expected.

Here's the Html (truncated to necessary, and sensitive information deleted):

<html>
<select id="one-time-payment-form:vendor-select-supplier">
    <option value="1848">Frarma Express</option>
    <option value="2119">Maderas Garcia</option>
    <option value="1974">Miaris, S.A.</option>
    <option value="3063">Ricoh Panama</option>
    <option value="3840">UNO EXPRESS</option>
    <option value="68">Garrett Blaser Gretsch</option>
    <option value="102">Oriel Antonio Grau</option>
</select>
</html>

And here is the code:

const string xpath = "//*[contains(@id, 'one-time-payment-form:vendor-select-')]/option[contains(text(), 'UNO EXPRESS')]";
var driver = new FirefoxDriver(new FirefoxProfile()) { Url = "PATH_TO_FILE_CONTAINING_HTML_SHOWN_ABOVE" };
Thread.Sleep(2000);

//Can WebDriver find it?
var e = driver.FindElementByXPath(xpath);
Console.WriteLine(e!=null ? "WebDriver success" : "WebDriver failure");

//Can Html Agility Pack find it?
var source = driver.PageSource;
var htmlDoc = new HtmlDocument { OptionFixNestedTags = true };
HtmlNode.ElementsFlags.Remove("form");
htmlDoc.LoadHtml(source);
var nodes = htmlDoc.DocumentNode.SelectNodes(xpath);
Console.WriteLine(nodes!=null ? "Html Agility Pack success" : "Html Agility Pack failure");

driver.Quit();

When I run the code, the console reads:

WebDriver success
Html Agility Pack failure

So WebDriver has no problem finding the @XPath element //*[contains(@id, 'one-time-payment-form:vendor-select-')]/option[contains(text(), 'UNO EXPRESS')], but the Html Agility Pack cannot.

Any ideas?

+3
source share
1 answer

" ". OPTION FORM. - - Html Agility Pack. HTML 3.2 OPTION , HTML 3.2 .

:

HtmlNode.ElementsFlags.Remove("option");
+5

All Articles