2016-11-16 55 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'] 
相關問題