hirurg103 / capybara_select2 Goto Github PK
View Code? Open in Web Editor NEWCapybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
License: MIT License
Capybara helpers for https://select2.org select box (supports Select2 version 2/3/4)
License: MIT License
This code fails:
within('#someModal') do
select2 'some_tag', from 'Tags', tag: true
end
is failing with:
Unable to find visible css ".select2-container-active .select2-result,.select2-drop-active .select2-result,.select2-results .select2-results
__option" with text "some_tag" within #<Capybara::Node::Element tag="div" path="/html/body/div[@id='modalBlock']/div[@id='someModal']"
This is because the selected option is added to a container outside the modal
Maybe https://github.com/Hirurg103/capybara_select2/blob/master/lib/capybara_select2/helpers.rb#L42 should search from the body?
Thank you for reviving this gem!
Hi,
See
I think the operation select2 @manager.name, css: '.membership_contact_id'
should be idempotent; it should not matter if the option was already selected.
I believe we could fix this this changing line:
53a9bf4#diff-ae92043bee3928497c5f6e5365d219bdL30-R30
to:
'4' => ".select2-results .select2-results__option"
I am not sure if we need the test helpers below so I am asking for the community help.
Please add ๐ if you need the helpers or ๐ if you think they are not necessary
# open select2 widget
select2_open css: '.select2'
select2_open label: 'Todo'
# close select2 widget
select2_close css: '.select2'
select2_close label: 'Todo'
# type into the search field within an opened select2 widget
select2_search 'Minsk'
# select an option from an opened select box
select2_select_option 'Buy Milk'
If you think that only some of the helpers above might be useful please add your opinion in the comments below
Let's say we have a form which requires users to fill fields for two comments. Each comment has the same set of fields, including a Type
field which is a select2
dropdown. Ideally, wrapping the select2
call around within
should do the trick but that's not happening.
The following snippet
within '#comment_1` do
select2 'Note', from: 'Type'
end
results in the following error
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching visible css ".select2-results .select2-results__option[aria-selected='false']" within #<Capybara::Node::Element tag="body" path="/HTML/BODY[1]">
because there is another Type
dropdown within #comment_2
.
Seems to me, the problem is that the method referenced below does not takes within
into consideration.
Also, seems to be related to #1.
I spent about an hour trying to figure out what selector (#my_selector) was being used. I tried the id of the select tag in question, then looked for options to pass an explicit id to select2, then spend time reading through your source code.
It was only after reading your own specs, and your HTML files that I discovered how to use your code. I appreciate your work, and that you've made it available, but it is extremely frustrating to have to do this.
It was not clear until then that #my_selector is an unrelated unique parent of the select2 element being targeted...
Hi @Hirurg103
I upgraded to version 0.2.1
but when I run the specs I get:
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/bundler-1.16.3/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require': There wa
s an error while trying to load the gem 'capybara-select-2'.
Gem Load Error is: undefined method `configure' for RSpec:Module
Backtrace for gem load error is:
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/capybara-select-2-0.2.1/lib/capybara_select2.rb:10:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.5.1@ideas4all-brasaas/gems/capybara-select-2-0.2.1/lib/capybara-select-2.rb:1:in `<top (required)>'
....
Maybe some require
is needed to use Rspec.configure
?
I'm using a select2 element with the tag option. When I use select2 'something', from: 'Something', tag: true
I get the error:
Capybara::ElementNotFound:
Unable to find css ".select2-container--open input.select2-search__field" within #<Capybara::Node::Element tag="body" path="/HTML/BODY[1]">
When I look at the code on the page, the .select2-search__field
element is a textarea rather than an input. I think that's reflected in the select2 code here
I think additional search input selectors are needed. If I add this before select2
call:
CapybaraSelect2::Selectors::SearchInputSelectors = {'4' => ".select2-container--open textarea.select2-search__field" }
The test runs without error.
After upgrading to Ruby 2.7, this warning started showing up:
lib/capybara_select2/helpers.rb:50: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
Hi there,
Just installed capybara-select-2. I'm generating a select2 from a grouped select:
= f.select(:for_programme_ids, Programme.grouped_options_for_select, {}, multiple: true, class: 'form-control select select2')
I'm trying to select an option:
select2(project1.programmes[0].name, from: 'Programmes', search: true)
and getting this error:
Capybara::ElementNotFound: Unable to find css ".select2-results .select2-results__option[role='treeitem']" within #<Capybara::Node::Element tag="body" path="/HTML/BODY[1]">
I'm using CapybaraSelect2 0.4.2, Select2 4.0.12, Capybara 3.29.0, rspec-core 3.8.2, rspec-rails 3.8.3, Ruby 2.5.3 and Rails 5.2.3.
When I inspect the HTML, the options have role="option"
, not role="treeitem"
.
Any idea what the issue is or what to do about it?
Thanks :)
I don't really have an issue, but I just wanted to say thanks for making this and keeping it up to date. I recently updated select-2 and realized my tests started failing. I was delighted to see you had already addressed it in the new version of the gem.
Feel free to close this issue. I just wan't sure where to say thanks!
Thanks for this nice library. :)
Can I ask you to cut a new release - I am hoping that maybe changes on master fix some random crashes we're experiencing...
Hi,
When I run a test that selects options from several select2 dropdowns I get the following error:
Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: Element <a href="javascript:void(0)" class="select2-choice select2-default" tabindex="-1">...</a> is not clickable at point (1119, 356). Other element would receive the click: <span title="...">Wed</span> (Session info: headless chrome=78.0.3904.70)
Select2 v3.5
Is there a way round this?
If I just select one dropdown it works fine, but if I run 2 it throws up the error.
select2 'cart', from: 'Status'
select2 'paid', from: 'Payment State'
click_on 'Filter Results'
What about helpers for asserting select2
content?
Something like:
expect(select2(from: 'Things to do')).to have_content(['one', 'two', 'three'])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.