msmith1114
msmith1114

Reputation: 3229

Dropdown select in Capybara with no id?

So I have a few dropdowns im making some automated test cases for (just checking to make sure links work and go to the right location. Easy test cases to toss in there)

But I don't really have any id's or anything to work with:

Here is the outer HTML of the Dropdown text to click (which reveals more dropdowns).

<a href="#" data-toggle="dropdown"><i class="glyphicon glyphicon-list-alt"></i> Main Dropdown <b class="caret"></b></a>

The rest of the items are listed like this:

<li><a href="/quotes"><i class="glyphicon glyphicon-list"></i> Option 1</a></li>

Would it make more sense to just try to use the clickable text to click on the "Main Dropdown" text and then the clickable text to click on "Option 1" (names were changed but the concept is still the same).

Since that's really all the HTML is in there?

Upvotes: 0

Views: 262

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49880

Capybaras link finder finds link elements by id, text, title or contained images alt attribute. With the html provided your best best for those is the text - so

click_link('Main Dropdown') # open the dropdown
click_link('Option 1') # wait for the link to become visible and then click it

Upvotes: 1

Related Questions