3

在动态网页上,我不知道预先匹配元素的数量,所以我不知道要使用哪个索引 #。

watir-webdriver 是否提供了一种访问 LAST 匹配元素的方法,而不是默认情况下首先访问?

有问题的 HTML 形成了一个日历控件

<table border="0" class="body-style">
  <tbody>
    <tr>
      <td width="27" align="right"><b>Sun</b></td>
      <td width="27" align="right"><b>Mon</b></td>
      <td width="27" align="right"><b>Tue</b></td>
      <td width="27" align="right"><b>Wed</b></td>
      <td width="27" align="right"><b>Thu</b></td>
      <td width="27" align="right"><b>Fri</b></td>
      <td width="27" align="right"><b>Sat</b></td></tr>
    <tr>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;1Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;2Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;3Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;4Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;5Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;6Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;7Â&nbsp;</p></td></tr>
    <tr>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;8Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;9Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;10Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;11Â&nbsp;</p></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;12Â&nbsp;</p></td>
      <td align="right"><a class="current-day-style selected-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=13;closeCalendar();doOtherFunctions();">Â&nbsp;13Â&nbsp;</a></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;14Â&nbsp;</p></td></tr>
    <tr>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;15Â&nbsp;</p></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=16;closeCalendar();doOtherFunctions();">Â&nbsp;16Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=17;closeCalendar();doOtherFunctions();">Â&nbsp;17Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=18;closeCalendar();doOtherFunctions();">Â&nbsp;18Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=19;closeCalendar();doOtherFunctions();">Â&nbsp;19Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=20;closeCalendar();doOtherFunctions();">Â&nbsp;20Â&nbsp;</a></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;21Â&nbsp;</p></td></tr>
    <tr>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;22Â&nbsp;</p></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=23;closeCalendar();doOtherFunctions();">Â&nbsp;23Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=24;closeCalendar();doOtherFunctions();">Â&nbsp;24Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=25;closeCalendar();doOtherFunctions();">Â&nbsp;25Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=26;closeCalendar();doOtherFunctions();">Â&nbsp;26Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=27;closeCalendar();doOtherFunctions();">Â&nbsp;27Â&nbsp;</a></td>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;28Â&nbsp;</p></td></tr>
    <tr>
      <td align="right"><p class="end-of-weekday-style">Â&nbsp;29Â&nbsp;</p></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=30;closeCalendar();doOtherFunctions();">Â&nbsp;30Â&nbsp;</a></td>
      <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=31;closeCalendar();doOtherFunctions();">Â&nbsp;31Â&nbsp;</a></td></tr>
  </tbody>
</table>
4

2 回答 2

12

试试这个(示例假设您正在寻找 div 元素)

browser.divs(:how => 'what').last

大多数元素的复数形式将返回匹配元素的集合(例如,在元素/标签名称中添加ses适当。div -> divs,地址 -> 地址)和 Ruby,这是一种很棒的语言,它有一种快速的方法通过该.last方法获取集合中的最后一个元素。

于 2012-01-14T00:40:20.850 回答
0

tmp 帖子。

有问题的 HTML 是一个弹出式日历:

<table border="0" class="body-style">
  <tbody>
    <tr>
        <td width="27" align="right"><b>Sun</b>
        </td>
        <td width="27" align="right"><b>Mon</b>
        </td>
        <td width="27" align="right"><b>Tue</b>
        </td>
        <td width="27" align="right"><b>Wed</b>
        </td>
        <td width="27" align="right"><b>Thu</b>
        </td>
        <td width="27" align="right"><b>Fri</b>
        </td>
        <td width="27" align="right"><b>Sat</b>
        </td>
    </tr>
    <tr>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;1Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;2Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;3Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;4Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;5Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;6Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;7Â&nbsp;</p>
        </td>
    </tr>
    <tr>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;8Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;9Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;10Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;11Â&nbsp;</p>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;12Â&nbsp;</p>
        </td>
        <td align="right"><a class="current-day-style selected-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=13;closeCalendar();doOtherFunctions();">Â&nbsp;13Â&nbsp;</a>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;14Â&nbsp;</p>
        </td>
    </tr>
    <tr>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;15Â&nbsp;</p>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=16;closeCalendar();doOtherFunctions();">Â&nbsp;16Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=17;closeCalendar();doOtherFunctions();">Â&nbsp;17Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=18;closeCalendar();doOtherFunctions();">Â&nbsp;18Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=19;closeCalendar();doOtherFunctions();">Â&nbsp;19Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=20;closeCalendar();doOtherFunctions();">Â&nbsp;20Â&nbsp;</a>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;21Â&nbsp;</p>
        </td>
    </tr>
    <tr>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;22Â&nbsp;</p>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=23;closeCalendar();doOtherFunctions();">Â&nbsp;23Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=24;closeCalendar();doOtherFunctions();">Â&nbsp;24Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=25;closeCalendar();doOtherFunctions();">Â&nbsp;25Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=26;closeCalendar();doOtherFunctions();">Â&nbsp;26Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=27;closeCalendar();doOtherFunctions();">Â&nbsp;27Â&nbsp;</a>
        </td>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;28Â&nbsp;</p>
        </td>
    </tr>
    <tr>
        <td align="right">
            <p class="end-of-weekday-style">Â&nbsp;29Â&nbsp;</p>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=30;closeCalendar();doOtherFunctions();">Â&nbsp;30Â&nbsp;</a>
        </td>
        <td align="right"><a class="normal-day-style" onmousemove="window.status=&quot; &quot;" onmouseout="window.status=&quot; &quot;" title="" href="javascript:dateSelected=31;closeCalendar();doOtherFunctions();">Â&nbsp;31Â&nbsp;</a>
        </td>
    </tr>
</tbody>

于 2012-01-14T19:14:22.600 回答