Reputation: 111
I'm having a problem with my dropdown, It uses selectize to make the dropdown, but when the number of options is too big it adds a scroll to the dropdown and when I try to click in some option that is not seen (that you need to scroll it to see) the capybara thinks the option is there and click out of the input where the option would be without scrolling. There's nothing changing the visibility (ordering it to search for not visible elements don' work either)
Upvotes: 0
Views: 804
Reputation: 7411
you can click a visible element in drop-down than send the :arrow_down
native key to simulate down key action. You should do this until the element visible, then click the active
option.
Check this for selectize.js home page:
find("#select-country-selectized").click()
while(true)
break if find(".option.active").text == "Benin"
find("#select-country-selectized").native.send_keys(:arrow_down)
end
find(".option.active").click
Upvotes: 2
Reputation: 111
The example of gunesmes was very helpfull, I made some changes like making the break one line up because otherwhise it would always jump the first option and changing the find for has_css? because find returns an error and has_css? returns true or false. I also changed the first find because I use cocoon and I need always to fill the last input generated. The final result was like this:
def scroll_dropdown(user)
all('input[id$="_user_id-selectized"]').last.click
while(true)
break if page.has_css?(".option.active", text: user, match: :prefer_exact, wait: false)
all('input[id$="_user_id-selectized"]').last.native.send_keys(:arrow_down)
end
find(".option.active").click
end
Upvotes: 0