使用CSS Selector获取行元素

时间:2013-11-11 03:04:22

标签: css-selectors selenium-ide

这是我的代码

<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>

我在Selenium中使用这个CSS选择器代码

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

它总是选择第一行而不是第二行。有什么想法吗? (我删除了stillig标签becoz代码真的很长)

1 个答案:

答案 0 :(得分:1)

我做了一些涉及tr标签的尝试,都使用CSS和XPATH,但在我看来tr在定位器中表现得很奇怪。

如果您没有明确需要使用tr,而是可以选择您的唯一输入后面的复选框,请尝试使用

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

相关问题