Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Follow the code below exactly matched with your case.</p> <ol> <li>Create an interface of the web element for the div under div with <strong>class</strong> as <strong>facetContainerDiv</strong></li> </ol> <p>ie for</p> <pre><code>&lt;div class="facetContainerDiv"&gt; &lt;div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>2. Create an IList with all the elements inside the second div i.e for,</p> <pre><code>&lt;label class="facetLabel"&gt; &lt;input class="facetCheck" type="checkbox" /&gt; &lt;/label&gt; &lt;label class="facetLabel"&gt; &lt;input class="facetCheck" type="checkbox" /&gt; &lt;/label&gt; &lt;label class="facetLabel"&gt; &lt;input class="facetCheck" type="checkbox" /&gt; &lt;/label&gt; &lt;label class="facetLabel"&gt; &lt;input class="facetCheck" type="checkbox" /&gt; &lt;/label&gt; &lt;label class="facetLabel"&gt; &lt;input class="facetCheck" type="checkbox" /&gt; &lt;/label&gt; </code></pre> <p>3. Access each check boxes using the index</p> <p>Please find the code below </p> <pre><code>using System; using System.Collections.Generic; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; namespace SeleniumTests { class ChechBoxClickWthIndex { static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("file:///C:/Users/chery/Desktop/CheckBox.html"); // Create an interface WebElement of the div under div with **class as facetContainerDiv** IWebElement WebElement = driver.FindElement(By.XPath("//div[@class='facetContainerDiv']/div")); // Create an IList and intialize it with all the elements of div under div with **class as facetContainerDiv** IList&lt;IWebElement&gt; AllCheckBoxes = WebElement.FindElements(By.XPath("//label/input")); int RowCount = AllCheckBoxes.Count; for (int i = 0; i &lt; RowCount; i++) { // Check the check boxes based on index AllCheckBoxes[i].Click(); } Console.WriteLine(RowCount); Console.ReadLine(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload