Nitesh
Nitesh

Reputation: 575

Using CSS Selector to get row element

This is my code

<tr>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input id="productLine_software-0" name="productLine_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Core</span>
            <input id="productCategory_software-0" name="productCategory_software" value="Core" type="hidden"/>
        </div>      
    </td>
    <td>
        <div>
            <span>Cloud Antispam</span>
            <input id="softwareName_software-0" name="softwareName_software" value="Cloud Antispam" type="hidden"/>
        </div>      
    </td>
    <td>
        <div>
            <div>
                <span>
                    <input id="select_boolean_software_1" type="checkbox" value="1" name="select_boolean_software"/>                        
                </span>
            </div>
        </div>      
    </td>
</tr>
<tr>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input name="productLine_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Core</span>
            <input id="productCategory_software-0" name="productCategory_software" value="Core" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <span>Cloud Email Security</span>
            <input name="softwareName_software" value="Cloud Email Security" type="hidden"/>
        </div>          
    </td>
    <td>
        <div>
            <div>
                <span>
                    <input id="select_boolean_software_1" type="checkbox" value="1" name="select_boolean_software"/>                        
                </span>
            </div>
        </div>      
    </td>
</tr>

I am using this CSS selector code in Selenium

css=tr:contains('Cloud Email Security & Content Control') input[type = 'checkbox']

It always select the first row instead of 2nd one. Any thoughts? (I deleted remainig tags becoz the code was really long)

Upvotes: 0

Views: 1338

Answers (1)

AnnTea
AnnTea

Reputation: 532

I did a few few attempts involving the tr tag, both using CSS and XPATH, but seems to me the tr is acting weird in the locator.

If you don't explicitly need to use the tr, and instead can go for the checkbox following your unique input, try this

xpath=//input[@name='softwareName_software' and @value='Cloud Email Security']/following::input[@type='checkbox']

Upvotes: 1

Related Questions