2016-11-16 71 views
0

我在xpath select中遇到了一些麻烦。Xpath选择生成表格的Div中前同步复选框

目前我使用C#和硒

我试图克服的问题,由此我需要一个生成的表中选择一个复选框,而只知道一个文本行的前同辈事业部。所有ID都可以随机生成。

我想选择类=“JQX-复选框 - 检查 - 检查”,而只知道文本“TESTDATA”

<div role="row" style="position: relative; height:28px;" id="row1jqxgrid"> 
    <div role="gridcell" style="left: 0px; z-index: 790; width:30px;" class="jqx-grid-cell jqx-item jqx-grid-cell-alt jqx-grid-cell-selected jqx-fill-state-pressed"> 
     <div style="position: absolute; top: 50%; left: 50%; margin-top: -7px; margin-left: -10px; overflow: visible; cursor: auto;" id="jqxWidget3af6ac8d" tabindex="0" class="jqx-widget jqx-checkbox"> 
      <div class="jqx-checkbox-default jqx-fill-state-normal jqx-rc-all"> 
       <div style="width: 13px; height: 13px;"><span style="width: 13px; height: 13px;" class="jqx-checkbox-check-checked"></span></div> 
      </div> 
      <div style="clear: both;"></div> 
     </div> 
    </div> 
    <div role="gridcell" style="left: 30px; z-index: 789; width:25px;display: none;" class="jqx-grid-cell"></div> 
    <div role="gridcell" style="left: 30px; z-index: 789; width:200px;" class="jqx-grid-cell jqx-item jqx-grid-cell-alt jqx-grid-cell-selected jqx-fill-state-pressed"> 
     <div class="jqx-grid-cell-left-align" style="margin-top: 6px;"><a id="id_01" href="/test/testing?id_01=199">testdata</a></div> 
    </div> 
</div> 
+0

尝试'/ div [div [div [text()=“testdata”]]] // div/span' – Andersson

回答

0

您可以尝试选择包含任何地方字符串testdata并在该rowrow选择div与所需的类。

第一次尝试是:

//div[@class='row'][.//div[text()='testdata']]//span[@class='jqx-checkbox-check-checked'] 

这将是最简单的方法。

0

您可以testdata选择元素,去祖先格,然后去跨越,你需要:

//*[text()='testdata']/ancestor::div[@role='row']//span 

您还可以指定类跨度的CALSS或部分你需要:

//*[text()='testdata']/ancestor::div[@role='row']//span[contains(@class,'checked')] 

//*[text()='testdata']/ancestor::div[@role='row']//span[@class = 'jqx-checkbox-check-checked']