Watir单击向下滚动时不可见的下拉值

时间:2014-01-10 14:46:58

标签: watir-webdriver

我是网络应用自动化测试的新手。我正在使用watir-webdriver来自动化我们的应用程序功能测试。在此过程中,我们需要单击下拉列表并从下拉列表中选择一个值。我面临的问题是我能够点击下拉列表中可见的元素,但是当我尝试点击可见项目正下方的项目时,它会将默认值设置为下拉列表并且没有任何错误地退出。

我的HTML摘录:

  <td width="50%">
    <strong>Drop Down Header</strong>
    <br />
    <div style="POSITION: relative; TOP: 0px">
      <div class="SelectRight">Select Item...</div>
      <div style="Z-INDEX: 998; WIDTH: 717px; DISPLAY: none; TOP: 639px; LEFT: 21px" class="SelectTarget" id="currentSelectedOptions"
      originalparent="null">
        <iframe style="POSITION: absolute; FILTER: alpha(opacity=0); WIDTH: 100%; DISPLAY: block; HEIGHT: 150%; TOP: 0px; LEFT: 0px"
        marginheight="0" src="javascript:&#39;&#39;;" frameborder="0" marginwidth="0" scrolling="no" align="bottom"></iframe>
        <ul style="Z-INDEX: 998; WIDTH: 684px; HEIGHT: 200px" class="SelectOptions">
          <li>
            <a id="option_0" href="javascript:void(0)">Select Item...</a>
          </li>
          <li>
            <a id="option_1" href="javascript:void(0)">Item 1</a>
          </li>
          <li>
            <a id="option_2" href="javascript:void(0)">Item 2</a>
          </li>
          <li>
            <a id="option_3" href="javascript:void(0)">Item 3</a>
          </li>
          <li>
            <a id="option_4" href="javascript:void(0)">Item 4</a>
          </li>
          <li>
            <a id="option_5" href="javascript:void(0)">Item 5</a>
          </li>
          <li>
            <a id="option_6" href="javascript:void(0)">Item 6</a>
          </li>
          <li>
            <a id="option_7" href="javascript:void(0)">Item 7</a>
          </li>
          <li>
            <a id="option_8" href="javascript:void(0)">Item 8</a>
          </li>
          <li>
            <a id="option_9" href="javascript:void(0)">Item 9</a>
          </li>
          <li>
            <a id="option_10" href="javascript:void(0)">Item 10</a>
          </li>
          <li>
            <a id="option_11" href="javascript:void(0)">Item 11</a>
          </li>
        </ul>
      </div>
    </div>
    <select id="dropDownItem" class="Shidden" name="dropDownItem" rows="3" wrap="soft">
      <option selected="selected" value="-1:::">Select Item...</option>
      <option value="291:::Item 1">Item 1</option>
      <option value="310:::Item 2">Item 2</option>
      <option value="350:::Item 3">Item 3</option>
      <option value="100:::Item 4">Item 4</option>
      <option value="102:::Item 5">Item 5</option>
      <option value="103:::Item 6">Item 6</option>
      <option value="104:::Item 7">Item 7</option>
      <option value="105:::Item 8">Item 8</option>
      <option value="106:::Item 9">Item 9</option>
      <option value="108:::Item 10">Item 10</option>
      <option value="109:::Item 11">Item 11</option>
    </select>
  </td>

我的Watir代码:

  contentframe = b.frame(:id => 'contentframe')
  contentframe.element(:xpath => "//td[contains(.,'Drop Down Header') and ./div/div[@class='SelectRight']]").click
  contentframe.element(:xpath => "//div[@id='currentSelectedOptions']/ul[@class='SelectOptions']/li/a[contains(.,'Item 9')]").click

如果有人可以指出我正确的方向来纠正这个

,那会有所帮助

谢谢, ARA

1 个答案:

答案 0 :(得分:0)

它真的很奇怪,而不是

contentframe.element(:xpath => "//div[@id='currentSelectedOptions']/ul[@class='SelectOptions']/li/a[contains(.,‌​'Item 9')]").click

我试过

contentframe.element(:xpath => "//div[@id='currentSelectedOptions']/ul[@class='SelectOptions']/li/a[contains(.,‌​'Item 9')]").fire_event 'onclick'

它工作了!!!