Here’s the markup:
<h3>Customers</h3>
<ul>
<li>
<label for="customer115">Some Customer Name</label>
<input id="customer115" type="checkbox" value="115" name="customer115">
</li>
.. there are more <li> here...and so on
</ul>
<h3>Dealers</h3>
<ul>
<li>
<label for="dealer100">Some DealerName</label>
<input id="dealer100" type="checkbox" value="115" name="dealer115">
</li>
.. there are more <li> here...and so on
</ul>
I’m trying to get reference to the customer checkbox for example so I can do a click() on it via XPath. I’m doing this in Selenium so something like:
string sXPath = string.Format(string.Format("//h3[text()='{0}']/ul/li/input[1]", "Customers"));
IWebElement firstCompanyCheckbox = GetElementByXPath(sXPath);
firstCompanyCheckbox.Click();
So far I can’t figure out how to get to this reference, the above xPath does not find it. I want to click that checkbox.
The
ulis not a child ofh3. It is a sibling. Adjust your XPath to use thefollowing-sibling::axisIf you want to ensure that you select the first
uland the firstli, then add additional predicate filters: