Selenium Webdriver - JAVA:从网格视图中选择项目

时间:2017-09-25 09:59:49

标签: java selenium selenium-webdriver

Selenium Webdriver - JAVA:

如何从gird视图表中选择特定项目,如下面的快照所示: Table View

HTML code:

<div id="pnlTreeHeadNode" class="x-panel" style="width: 764px;">
   <div class="x-panel-bwrap" id="ext-gen193">
      <div class="x-panel-body x-panel-body-noheader" id="ext-gen194" style="height: 228px; width: 762px;">
         <div id="TreeOSView" class=" x-panel x-tree">
            <div class="x-panel-bwrap" id="ext-gen455">
               <div class="x-panel-body x-panel-body-noheader" id="ext-gen456" style="overflow: auto; position: relative; height: 228px;">
                  <ul class="x-tree-root-ct x-tree-lines" id="ext-gen457">
                     <li class="x-tree-node">
                        <div ext:tree-node-id="0" class="x-tree-node-el x-unselectable x-tree-node-expanded x-tree-selected" unselectable="on"><span class="x-tree-node-indent"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow-end-minus"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon btn-main-style dt-btn-people" unselectable="on"><a hidefocus="on" class="x-tree-node-anchor" href="#" tabindex="1"><span unselectable="on">Root Node</span></a></div>
                        <ul class="x-tree-node-ct" style="">
                           <li class="x-tree-node">
                              <div ext:tree-node-id="1" class="x-tree-node-el x-unselectable x-tree-node-collapsed" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow-plus"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon btn-main-style dt-btn-people" unselectable="on"><a hidefocus="on" class="x-tree-node-anchor" href="#" tabindex="1"><span unselectable="on">Administration  | General Manager | Jihad</span></a></div>
                              <ul class="x-tree-node-ct" style="display:none;"></ul>
                           </li>
                           <li class="x-tree-node">
                              <div ext:tree-node-id="1120" class="x-tree-node-el x-unselectable x-tree-node-collapsed x-tree-node-over" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow-end-plus"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon btn-main-style dt-btn-people" unselectable="on"><a hidefocus="on" class="x-tree-node-anchor" href="#" tabindex="1"><span unselectable="on">Department 22 | Funtion 22 | user 23</span></a></div>
                              <ul class="x-tree-node-ct" style="display:none;"></ul>
                           </li>
                        </ul>
                     </li>
                  </ul>
               </div>
            </div>
         </div>
         <input type="hidden" size="20" autocomplete="off" id="TreeOSView_SM" name="TreeOSView_SM" class=" x-form-hidden x-form-field" value="{&quot;nodeID&quot;:&quot;0&quot;,&quot;text&quot;:&quot;Root Node&quot;,&quot;path&quot;:&quot;/0&quot;,&quot;attributes&quot;:{&quot;nodeType&quot;:&quot;async&quot;}}"><input type="hidden" size="20" autocomplete="off" id="TreeOSView_CheckNodes" name="TreeOSView_CheckNodes" class=" x-form-hidden x-form-field" value="">
      </div>
   </div>
</div>

1 个答案:

答案 0 :(得分:0)

要识别级别1 /根节点,您可以尝试:

//ul[@class='x-tree-root-ct x-tree-lines']/li/div/a[@class='x-tree-node-anchor']

并确定2级列表项,您可以尝试:

//ul[@class='x-tree-node-ct']//a[@class='x-tree-node-anchor']