CSS'包含'selector&升级水豚 [英] CSS 'contains' selector & upgrade of Capybara
问题描述
以前,我的规格有这些行:
Previously my specs had these lines:
within "h3:contains('FooBar text') + dl" do
page.should have_content 'FizzBuzz'
end
我升级了capybara-webkit,现在'contains'选择器不起作用
(这是一个很好的,可以理解的因为它已在CSS3中弃用)。
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?
推荐答案
我认为你不仅升级了capybara-webkit而且升级了capybara。
I think you upgraded not only capybara-webkit but also capybara.
Capybara 2.1现在使用了CSS选择器的驱动程序实现。
Capybara 2.1 now uses driver's implementation of CSS selectors.
以前它的工作原因是因为Capybara使用Nokogiri将CSS选择器转换为XPath。 Nokogiri似乎支持:包含
伪选择器(此代码以前工作)。
Previously it worked because Capybara converted CSS selector to XPath using Nokogiri. Nokogiri seems to support :contains
pseudo selector (as this code worked previously).
您可以使用XPath如:
You can rewrite it using XPath like:
within(:xpath, "//dl[preceding-sibling::h3[contains(text(),'FooBar text')]]") do
page.should have_content 'FizzBuzz'
end
$ b b
但是,我认为它不太容易阅读,所以最好选择一个更简洁易读的更好的选择器。
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.
这篇关于CSS'包含'selector&升级水豚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!