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 am trying to click the first checkbox that says "Select all" so that all the other checkboxes below are selected.

I think my C# code is suppose to load the HtmlNode but I can't figure out how to click it.

Any suggestions would be helpful.

5/14/2015 4:59:11 PM

Accepted Answer

I don't think you can use HtmlAgilityPack to check a checkbox. Yes you can change the dom in your doc object so that the checkbox is checked and set the DocumentText of the webbrowser control as your htmldocument but I doubt that's what you want to do.

If you have the page open in the webBrowser, you can use something like this:


But this will only select the first checkbox.

If you want all checkboxes to be selected, you can either iterate the above code for all input elements or use server side javascript to check all checkboxes when the first checkbox is checked.

Again, I can help you further if you explain what you want a little bit more clearly.

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