Reputation: 18419
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.
Test Case:
Upvotes: 1
Views: 4136
Reputation: 699
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.
Upvotes: 0