Selenium Webdriver - 选择树节点中的项目

时间:2014-01-17 00:45:32

标签: java selenium selenium-webdriver

我正在尝试选择树节点中的某些项目。理想情况下,我想做以下事情:

1)根据项目文本从树视图中选择“Child Item One”。

这是Tree对象的HTML:

 <div id="form:treeSingle" class="ui-tree ui-widget ui-widget-content ui-corner-all 
          treeMenu" aria-multiselectable="true" role="tree">
    <ul class="ui-tree-container">
       <li id="form:treeSingle:0" class="ui-treenode ui-treenode-parent ui-treenode-
              unselected" role="treeitem" data-nodetype="default" data-rowkey="0">
         <span class="ui-treenode-content ui-tree-selectable" aria-selected="false" 
                       aria-expanded="true">
            <span class="ui-tree-toggler ui-icon ui-icon-triangle-1-s"/>
          <span/>
          <span class="ui-treenode-label ui-corner-all ui-state-hover">Top Level 
                     Perm</span>
          </span>
             <ul class="ui-treenode-children">
                <li id="form:treeSingle:0_0" class="ui-treenode ui-treenode-parent 
                        ui-treenode-selected" role="treeitem" data-
                        nodetype="default" data-rowkey="0_0">
                    <span class="ui-treenode-content ui-tree-selectable" aria- 
                          selected="true" aria-expanded="true">
                       <span class="ui-tree-toggler ui-icon ui-icon-triangle-1-s"/>
                    <span/>
                    <span class="ui-treenode-label ui-corner-all ui-state-
                          highlight">Child Item One</span>
                    </span>

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

请参阅入门示例here,您的xpath应如下所示:

driver.findElements(By.xpath("//span[text()='Child Item One']"))