Previously my specs had these lines:
within "h3:contains('FooBar text') + dl" do
page.should have_content 'FizzBuzz'
end
(within definition list next from header that contains specified text)
I upgraded capybara-webkit and now 'contains' selector does not work
(which is kind a fine and understandable since it's deprecated in CSS3).
I can't figure out an easy way to rewrite this. Any ideas?
The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.
Simply right click and click Inspect Element. This will bring up the CSS selectors for that element.
If you want to avoid having to figure out the xpath, you can use Nokogiri::CSS.xpath_for It returns an array so you need to do [0]
within :xpath, Nokogiri::CSS.xpath_for("<CSS SELECTOR>")[0] do
I think you upgraded not only capybara-webkit but also capybara.
Capybara 2.1 now uses driver's implementation of CSS selectors.
Previously it worked because Capybara converted CSS selector to XPath using Nokogiri. Nokogiri seems to support :contains pseudo selector (as this code worked previously).
You can rewrite it using XPath like:
within(:xpath, "//dl[preceding-sibling::h3[contains(text(),'FooBar text')]]") do
page.should have_content 'FizzBuzz'
end
However, I think it's not too readable so it may be better to choose a better selector that will be more short and readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With