我是Capybara的新手,我需要选择星期三在同一列中的复选框。我该如何选择它?我试过几种方法,但我仍然得到这个错误,找不到元素。
HTML部分如下所示:
<table class="grid">
<thead>
<tr>
<th colspan="1" rowspan="1" style="width: 56px;">From</th>
<th colspan="1" rowspan="1" style="width: 56px;">To</th>
<th colspan="1" rowspan="1">Monday</th>
<th colspan="1" rowspan="1">Tuesday</th>
<th colspan="1" rowspan="1">Wednesday</th>
<th colspan="1" rowspan="1">Thursday</th>
<th colspan="1" rowspan="1">Friday</th>
<th colspan="1" rowspan="1">Saturday</th>
<th colspan="1" rowspan="1">Sunday</th>
<th colspan="1" rowspan="1" style="width: 18px;"></th>
</tr>
</thead>
<tbody>
<tr class="t-forminjector" id="rowInjector_1470ffb567f" style=
"background-image: none; background-color: rgba(0, 0, 0, 0);">
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml">
<input name="t:formdata" type="hidden" value=
"H4sIAAIDOPgvsNqt">
<div class="timepicker"><input class=
"timepicker-input patternDailyStart hasDatepicker" id=
"patternDailyStart_1470ffb567f" name=
"patternDailyStart_1470ffb567f" type="text" value="">
<img alt="..." class="ui-datepicker-trigger" src=
"clock.png" title="..."></div><img alt="" class=
"t-error-icon" id="patternDailyStart_1470ffb567f_icon" src=
"spacer.gif" style="display: none;">
</td>
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml">
<div class="dailyEnd">
<div class="timepicker"><input class=
"timepicker-input patternDailyEnd hasDatepicker" id=
"patternDailyEnd_1470ffb567f" name=
"patternDailyEnd_1470ffb567f" type="text" value="">
<img alt="..." class="ui-datepicker-trigger" src=
"clock.png" title="..."></div><img alt="" class=
"t-error-icon" id="patternDailyEnd_1470ffb567f_icon" src=
"spacer.gif" style="display: none;"></div>
</td>
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml"><input id="checkbox_1470ffb567f"
name="checkbox_1470ffb567f" type="checkbox"> <img alt="" class=
"t-error-icon" id="checkbox_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml"><input id=
"checkbox_0_1470ffb567f" name="checkbox_0_1470ffb567f" type=
"checkbox"> <img alt="" class="t-error-icon" id=
"checkbox_0_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml"><input id=
"checkbox_1_1470ffb567f" name="checkbox_1_1470ffb567f" type=
"checkbox"> <img alt="" class="t-error-icon" id=
"checkbox_1_1470ffb567f_icon" style="display: none;"></td>
<td colspan="1" rowspan="1"><input id="checkbox_2_1470ffb567f"
name="checkbox_2_1470ffb567f" type="checkbox"> <img alt=""
class="t-error-icon" id="checkbox_2_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1"><input id="checkbox_3_1470ffb567f"
name="checkbox_3_1470ffb567f" type="checkbox"> <img alt=""
class="t-error-icon" id="checkbox_3_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1"><input id="checkbox_4_1470ffb567f"
name="checkbox_4_1470ffb567f" type="checkbox"> <img alt=""
class="t-error-icon" id="checkbox_4_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1"><input id="checkbox_5_1470ffb567f"
name="checkbox_5_1470ffb567f" type="checkbox"> <img alt=""
class="t-error-icon" id="checkbox_5_1470ffb567f_icon" src=
"/mpromoter/assets/8fe900a87e3fabc9/core/spacer.gif" style=
"display: none;"></td>
<td colspan="1" rowspan="1" xmlns=
"http://www.w3.org/1999/xhtml">
<a href="#" id="removerowlink_1470ffb567f"><img alt="" src=
"/mpromoter/assets/8fe900a87e3fabc9/ctx/images/delete.ico"
title="Remove"></a>
</td>
</tr>
<tr class="t-forminjector" id="rowInjector">
<td></td>
</tr>
</tbody>
</table>
当我复制xpath时,它看起来像这样://*[@id="checkbox_1_1470ffb567f"]
该复选框的ID每次都不同(最后每次打开页面时这些数字都会改变。)但是checkbox_1部分是相同的。
答案 0 :(得分:0)
您可以使用contains()
功能:
//*[contains(@id, "checkbox_1_")]