2014-07-07 41 views
0

我是新的水豚,我需要选择与星期三相同的列中的复选框。我怎样才能选择它?我尝试了几种方法,但我仍然得到这个错误,找不到元素。使用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

可以使用功能:

//*[contains(@id, "checkbox_1_")] 
相关问题