【发布时间】:2017-03-30 13:14:48
【问题描述】:
我在使用 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>
【问题讨论】:
-
试试
//div[div[div[text()="testdata"]]]//div/span