user2807487
user2807487

Reputation: 5

Watir: click on drop down menu with same attributes

<div class="subtab">
    <button class="ui-multiselect ui-widget ui-state-default ui-corner-all" type="button" aria-haspopup="true" style="width: 231px;">
        <span class="ui-icon ui-icon-triangle-2-n-s"></span>
            <span>None</span>
    </button>
    <button class="ui-multiselect ui-widget ui-state-default ui-corner-all" type="button" aria-haspopup="true" style="width: 231px;">
        <span class="ui-icon ui-icon-triangle-2-n-s"></span>
            <span>None</span>
    </button>
</div>

This is 2 drop down menu (the first one is right above the second one). They both have the exact same attribute. How do I specify which one to click on? I'm not even sure why they have the same exact attributes but they do.

Upvotes: 0

Views: 506

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

You can use the :index locator to specify which of the matching elements is returned. For example :index => 0 will return the first matching element, :index => 1 will return the second matching element, etc. Note that the :index is 0-based (ie starts at 0).

# To click the first one
browser.button(:class => class="ui-multiselect", :index => 0).click

# To click the second one
browser.button(:class => class="ui-multiselect", :index => 1).click

Upvotes: 1

Related Questions