Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:58:51+00:00 2026-05-22T22:58:51+00:00

This is related to my previous question , but it seems I have another

  • 0

This is related to my previous question, but it seems I have another corner case where Html Agility Pack doesn’t work as expected.

Here’s the Html (stripped down to the essentials, and sensitive information removed):

<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’s 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 clearly WebDriver has no problem locating the item @XPath //*[contains(@id, 'one-time-payment-form:vendor-select-')]/option[contains(text(), 'UNO EXPRESS')], but Html Agility Pack cannot.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:58:52+00:00Added an answer on May 22, 2026 at 10:58 pm

    This is “by design”. It’s the same idea for OPTION and FORM. Some tags are handled differently because of historical reasons by the Html Agility Pack. Back then in HTML 3.2 time, OPTION was not always closed, and in HTML 3.2, it’s not required.

    Try adding this:

    HtmlNode.ElementsFlags.Remove("option");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to my previous question , but a different one. I have
This is related to a previous question , but it seems different enough to
This is related to my previous question, but will navigator.onLine work if there is
Very much related to my previous question , but I found this to be
This question is related to my previous question . The storyline: I have an
This is a related to a previous question I have asked here, see the
This is related to my previous question but it is a different problem. I
This question ties to my previous question but is more specific. Say I have
This is related to a previous question I asked with Jquery. If I have
This is closely related to a previous question i asked. I have a many-to-many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.