我在选择xpath方面遇到了一些麻烦。
我目前正在使用C#和Selenium
我试图克服一个问题,我需要在生成的表格中选择一个复选框,同时只知道前一个兄弟Div中的一行文本。所有ID都可以随机生成。
我想选择class =" jqx-checkbox-check-checked"虽然只知道文本" 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 :(得分:0)
您可以尝试选择包含字符串row
的任何位置的testdata
,并在row
中选择包含所需类别的div
。
第一次尝试是:
//div[@class='row'][.//div[text()='testdata']]//span[@class='jqx-checkbox-check-checked']
这是最简单的方法。
答案 1 :(得分:0)
您可以选择testdata
元素,转到祖先div,然后转到您需要的范围:
//*[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']