0

I don't seem to be able to use click for checkboxes.
No error in the console, it shows the click but the checkbox isn't checked.
I have tried using both click and check but neither seem to check the checkbox. Using the database id (102) as suggested by the IDE recorder is not an option as the ID's change with each run.

I am trying: css=fieldset.choices ol li label input for my locator.

I also tried: //fieldset[@class='choices']//ol//li//label//input and again the console says clicked but the checkbox doesn't actually get checked in the browser.

I also tried: //input[@type='checkbox'] for the selector as it is the first checlbox on the screen but no luck with that, but no explicit error.

The HTML is:

<fieldset class="choices">
  <legend class="label">
    <label>
      Grades
    </label>
  </legend>
  <input id="school_grades_none" type="hidden" value="" name="school[grade_ids][]">
  </input>
  <ol class="choices-group">
    <li class="choice">
      <label for="school_grade_ids_102">
        <input id="school_grade_ids_102" type="checkbox" value="102" style="border: none" name="school[grade_ids][]">
        </input>
        PK3
      </label>
    </li>
    <li class="choice">
    ...
    </li>
    <li class="choice"></li>
    ...
    </li>
    <li class="choice"></li>
    ...
    </li>
    ...

2 Answers 2

1

How about when you use id=school_grade_ids_102 as your locator, instead of the xpath or css.

UPDATE

How about you use contains like so

//input[contains(@id, 'school_grade_ids_')] # add [1] or [2], etc. at the end
Sign up to request clarification or add additional context in comments.

1 Comment

Might be useful. I guess I would put a [1], [2], etc. after it to go after each checkbox?
0
setCheckboxValue(By.id("checkboxId"), true /* or false*/);

public void setCheckboxValue(By by, boolean checked) {
        WebElement e = getDriver().findElement(by);
        if(!e.isSelected() && checked) {
            e.click();
        }
    }

1 Comment

Thanks but not using Java/C just using the IDE, where would I put this in the IDE?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.