Friday, 7 January 2022

using nth-type or nth-child to select n element

What XPath or CSS selector I can use to select 2nd <div class="checkbox">? I have tried to use XPath //div[@class="checkbox"][2] or CSS selector div.checkbox:nth-child(2) none of them worked on chrome develop tool.

With $x('//div[@class="checkbox"]'), I can see three elements and I can use $x('//div[@class="checkbox"]')[0] to specify first div class=checkbox and $x('//div[@class="checkbox"]')[1] to specify the 2nd <div class="checkbox">

<div class="fs">
    <div class="f">
        <div class="checkbox">
            <input type="radio" value="A">
            <label for="A">A</label>
        </div>
    </div>
    <div class="f">
        <div class="checkbox">
            <input type="radio" value="B">
            <label for="B">B</label>
        </div>
    </div>
    <div class="f">
        <div class="checkbox">
            <input type="radio" value="C">
            <label for="C">C</label>
        </div>
    </div>
</div>


from using nth-type or nth-child to select n element

No comments:

Post a Comment