goodwill / capybara-select2

Helper for capybara to be able to trigger select on select2 javascript (needed for js enabled test only)
MIT License
80 stars 111 forks source link

Incompatible with optgroups? #46

Open abuisman opened 8 years ago

abuisman commented 8 years ago

Hi,

I am trying to select an option in my select2 that is inside an optgroup.

The error in capybara I get is:

Ambiguous match, found 2 elements matching css ".select2-dropdown li.select2-results__option" with text "Käpt’n Blaubär? (m)"

I called select2 like so:

select2 'Käpt’n Blaubär? (m)', css: '.select2-container'

My select2 with dummy data looks like this:

image

I suspect the ambiguity is caused by the fact that optgroups also have a 'select2-results__option' class:

<li aria-label="Boten" role="group" class="select2-results__option"><strong class="select2-results__group">Boten</strong>
        <ul class="select2-results__options select2-results__options--nested">
            <li aria-selected="false" role="treeitem" id="select2-name_of_my_select-result-hfih-4" class="select2-results__option select2-results__option--highlighted">Käpt’n Blaubär? (m)</li>
        </ul>
    </li>

So there are 2 elements that contain the text 'Käpt’n Blaubär? (m)', the group 'Boten' and the item itself.

A fix would be to add the role attribute into the selection for items [role=treeitem]

abuisman commented 8 years ago

Tested my PR in our project and it works. So feel free to test it yourself and merge when approved.

P.s. are there any specs? I didn't see them.

Zeragamba commented 8 years ago

Ran into this issue today as well. Any timeline for the merge?

ZASMan commented 5 years ago

Is there any updates on this? Seems that optgroup is incompatible with this.