1
votes

I got this List of checkboxes and I want to verify if the specific check box is checked or not, I can't use the checkbox id but only the text but it is like this.

<ul id="chkList">
    <li>
        <span>
            <input id="CheckBox_1" type="checkbox" value="1" checked="checked" />
            <label for="CheckBox_1">Cat</label>
        </span>
    </li>
    <li>
        <span>
            <input id="CheckBox_2" type="checkbox" value="20" />
            <label for="CheckBox_2">Dog</label>
        </span>
    </li>
    <li>
        <span>
            <input id="CheckBox_2" type="checkbox" value="22" />
            <label for="CheckBox_2">Alley</label>
        </span>
    </li>
</ul>

I want to do something like

driver.FindElement(By.XPath("//ul[@id='chkList']/li/span/label[./text()='Cat'])).Selected;

But surely I can't do that because the xpath selects the label not the input. I am thinking of using the for for the label to look for the id for input. But how can I do that?

I can't use the id for input and it's value because it is dynamic, the only thing I can use is the Text.

EDIT

Test Case:

  1. Create a new item in chkList
  2. Assign the new item by checking it with another item. (not shown for brevity)
  3. Save
  4. Verify if the new item is assigned to another item.
1
the best is to install Selenium IDE and copy out of the recorded test, that's what I do... still didn't get why you don't use the id btw - Franz Ebner
Frank, that's what I'm doing also but the <li> is created during the test, only the text is provided. The value is generated in db and id is appended by the value. So there's no way I know the ID. - rob waminal

1 Answers

0
votes

Have you tried with XPath like this:

driver.FindElement(By.XPath("//ul[@id='chkList']/li[1]/span/input)).Selected;

You can maintain one count for number of checklist and use that value with li[count] element.