How can I click a checkbox using HtmlAgilityPack

c# html-agility-pack


HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlNode n = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'checkbox')]");

<table class="list" cellspacing="0">
    <th width="45" class="checkAll"><input title="Select all" class="checkbox" type="checkbox" value=""></th>


    <th><span>Target system</span></th>

  <tr class="checkable">
    <td><input name="item1" class="checkbox" type="checkbox"></td>



  <tr class="checkable odd">
    <td><input name="item2" class="checkbox" type="checkbox"></td>



  <tr class="foot">
    <td colspan="4"><input name="SUBMIT" class="submit" type="submit" value="Unlock"></td>

I'm attempting to pick every checkbox below by clicking the first one that reads "Select all."

Although I believe my C# code is supposed to load the HTMLNode, I am unable to do it.

Any advice would be appreciated.

5/14/2015 4:59:11 PM

Accepted Answer

HtmlAgilityPack probably can't be used to check a checkbox. Undoubtedly, you may alter the dom in yourdoc a checkbox on an item, and then set theDocumentText I doubt that's what you want to do, however you could use the webbrowser control as your html document.

If the page is open in thewebBrowser you may use something similar to this:


But just the first checkbox will be selected by this.

You may either use server-side java script to check all checkboxes when the first checkbox is chosen or repeat the same code for all input items if you want all checkboxes to be selected.

Once again, if you could be a little clearer about what you want, I could assist you further.

5/14/2015 5:43:45 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow