Watir-webdriver, как получить доступ к последнему элементу соответствия не первым? - PullRequest
1 голос
/ 13 января 2012

На динамической веб-странице я не знаю количество подходящих элементов заранее, поэтому я не буду знать, какой индекс # использовать.

Предоставляет ли 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>

Ответы [ 2 ]

9 голосов
/ 14 января 2012

Попробуйте это (пример предполагает, что вы ищете элементы div)

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

Множественное число для большинства элементов вернет набор подходящих элементов (например, добавьте s или es к элементу /имя тега, как было бы уместно. div -> divs, address -> address) И Ruby, отличный язык, который имеет быстрый способ получить последний элемент в коллекции с помощью метода .last.

0 голосов
/ 14 января 2012

tmp post.

Рассматриваемый 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>

...