0
我可以使用水豚 - 如何根據多個屬性進行資格認證?
expect(page).to have_selector("label.field_with_errors")
和
expect(page).to have_selector("label[for='landing_zip_code']")
和他們的工作正常。
但是我想檢查它們在同一個領域是否都是真實的。
我已經試過:
expect(page).to
have_selector("label[class='field_with_errors']:and([for='landing_zip_code'])")
和
expect(page).to
have_selector("label[class='field_with_errors']") &&
have_selector('landing_zip_code')
但既不工作。 錯誤第2次嘗試:
Failure/Error: expect(page).to
have_selector("label[class='field_with_errors']") &&
have_selector('landing_zip_code')
expected to find css "landing_zip_code" but there were no matches
我也試過
expect(find("label[class='field_with_errors']")).to
have_attribute('for=landing_zip_code')
,但得到
Failure/Error: expect(find("label[class='field_with_errors']")).
to have_attribute('for=landing_zip_code')
expected #<Capybara::Node::Element:0x00003b5de90> to respond to `has_attribute?`
# ./spec/features/quote_spec.rb:65:in `block (3 levels) in <top (required)>'
我試圖
expect(find("label[class='field_with_errors']")['for=landing_zip_code']).to be
但得到
Failure/Error: expect(find("label[class='field_with_errors']")['for=landing_zip_code']).to be
expected nil to evaluate to true
您可以繼續以類似的方式檢查屬性:'label.field_with_errors [爲= 'landing_zip_code'] [other_attr =值1] [one_more_attr =數值]'。這是你問的嗎?謝謝。 – alecxe