2014-07-07 62 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_")] 
相關問題