0

I've been using Selenium with the product for a while.

Regular HTML pages, forms and javascript are working well with it.

Our developer just added an AJAX drop-down menu.

I can't 'record' that with selenium, how can I use it? Actually I can record that the control was initially clicked (which makes the drop-down appear) but not what option is then clicked. How can I then detect that they clicked on one of the options?

The HTML that's displayed is:

<ul id="fruit-switcher" class="nav nav-pills">
  <li class="dropdown">
    <a class="dropdown-toggle" href="#">
      Change fruit…
      <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
      <li>
        <a rel="nofollow" data-method="put" href="/admin/fruits/23-bananas/activate"></a>
      </li>
      <li>
        <a rel="nofollow" data-method="put" href="/admin/fruits/28-apples/activate"></a>
      <li>
      </li>
      <li>
        other options (a links)...
      </li>...
    </ul>
  </li>
</ul>
<script>

  //<![CDATA[
    $(function() {
      $('#fruit-switcher .dropdown-toggle').dropdown();
    })
  //]]>

</script>
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
  • You (or your developer) might be able to [add JQuery integration into Selenium](http://stackoverflow.com/questions/3235013/how-to-use-jquery-in-selenium), and then you could add tests using JQuery selectors. – mccannf Feb 14 '13 at 00:00

2 Answers2

0

You can always send_keys to the element.

Zach
  • 885
  • 2
  • 8
  • 27
0

Actually it was straight-forward selenium code:

click    link="Change..."
pause 200
click //ul[contains(@id,'fruit-switcher')]//ul[contains(@class,'dropdown-menu')]/li[3]/a
click    link="Change..."
pause 600
click //ul[contains(@id,'fruit-switcher')]//a[contains(text(),'Bananas')]
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497