如何使用其他相关元素单击元素?

时间:2013-09-19 15:24:24

标签: html selenium selenium-rc selenium-ide

<ul class="ui-treenode-children">
<li aria-selected="true" aria-checked="true" aria-expanded="true" id="frmScrForm:multiLevelTree:0_0" data-rowkey="0_0" class="ui-treenode ui-treenode-parent folder" role="treeitem">
    <span class="ui-treenode-content ui-tree-selectable" aria-expanded="false" aria-selected="false" aria-checked="false">
        <span class="ui-tree-toggler ui-icon ui-icon-triangle-1-s"></span>
        <div class="ui-chkbox ui-widget tree_node_folder_expand">
            <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
                <span class="ui-chkbox-icon ui-icon ui-icon-check"></span>
            </div>
        </div>
        <span class="ui-treenode-icon ui-icon tree_node_folder_collaps"></span>
        <span class="ui-treenode-label ui-corner-all">
            <span class="tree_node_folder_text" style="background-color: transparent;">Company</span>
        </span>
    </span>
    <ul class="ui-treenode-children" style="">
    </ul>
</li>
</ul>

我正在使用selenium(selenium IDE)来测试树,我想根据它旁边的文本(或值)点击复选框。

这是树中一个节点的HTML代码,如何在文本(公司)旁边的复选框中使用selenium?

1 个答案:

答案 0 :(得分:0)

请尝试使用以下xpath

selenium.click("xpath=//span[@class='ui-treenode-content ui-tree-selectable']
   [contains(text(),"Company")]/parent::span/span/div/div/span");