javascriptautomated-testsnightwatch

Having trouble selecting checkboxes


The checkbox on my page looks like this:

<td role="gridcell" style="width: 30px; padding:0;text-align: center;" class="ui-selection-column">
  <div class="ui-chkbox ui-widget">
    <div class="ui-helper-hidden-accessible"><input type="checkbox" name="dataTable_checkbox" aria-checked="false"></div>
    <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"><span class="ui-chkbox-icon ui-icon ui-c ui-icon-blank"></span></div>
  </div>
</td>

It's contained in a tbody and tr data.

I'm trying to select it by using

.click('input[id="ui-chkbox ui-widget", type="checkbox"]')

And I already tried using .waitForElementVisible and still couldn't select it.

Thanks.


Solution

  • Per your code here:

    .click('input[id="ui-chkbox ui-widget", type="checkbox"]')
    

    You are mistakenly identifying the classes ui-chkbox ui-widget as an id. Find the specific id on the page for that checkbox, if there is one, and select it using that. IDs on a page are specific to that element.

    .click('#youridhere')
    

    Alternatively, use Xpath and select it by its path containing any text.

    .click("//*[contains(text(), 'Checkbox text here')]")