使用 have_selector 的多个选择器
Multiple selectors using have_selector
我希望将我的发现转换为使用 have_selector。目前我的工作方式是:
expect(find('div[some-attr=true]'))['some-data-attr']).to eq('Hello World')
我希望将其转换为使用 have_selector 我试过了:
expect(page).to have_selector('div[some-attr=true][some-data-attr]')
我做错了什么?
这应该是
expect(page).to have_css('div[some-attr=true][some-data-attr="Hello World"]')
这仅在 'some-data-attr' 实际上不是自页面加载后已修改的 属性 时才有效。选择器匹配属性值,但由于您的原始方法在返回的元素上调用 #[]
,它可能一直在访问具有更改值的 属性。在不知道这些属性名称实际是什么以及它们是如何使用的情况下,无法确定。如果它实际上是一个 属性 并且您需要在您的应用程序中经常使用它,您可以在 :css 选择器
上编写一个自定义过滤器
If Capybara.default_selector == :css then have_selector
and have_css
mean the same thing, but if you're using a css selector then你最好只使用 have_css
我希望将我的发现转换为使用 have_selector。目前我的工作方式是:
expect(find('div[some-attr=true]'))['some-data-attr']).to eq('Hello World')
我希望将其转换为使用 have_selector 我试过了:
expect(page).to have_selector('div[some-attr=true][some-data-attr]')
我做错了什么?
这应该是
expect(page).to have_css('div[some-attr=true][some-data-attr="Hello World"]')
这仅在 'some-data-attr' 实际上不是自页面加载后已修改的 属性 时才有效。选择器匹配属性值,但由于您的原始方法在返回的元素上调用 #[]
,它可能一直在访问具有更改值的 属性。在不知道这些属性名称实际是什么以及它们是如何使用的情况下,无法确定。如果它实际上是一个 属性 并且您需要在您的应用程序中经常使用它,您可以在 :css 选择器
If Capybara.default_selector == :css then have_selector
and have_css
mean the same thing, but if you're using a css selector then你最好只使用 have_css