2015-06-28 21 views
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 

回答

0

在這(我是OP)我可以使用「.‘級和’#」標識要做到這一點,即

expect(page).to 
have_selector("label.field_with_errors[for='landing_zip_code']") 

但是我也想知道如何檢測除了班級和身份證以外還有其他多個屬性

+1

您可以繼續以類似的方式檢查屬性:'label.field_with_errors [爲= 'landing_zip_code'] [other_attr =值1] [one_more_attr =數值]'。這是你問的嗎?謝謝。 – alecxe

0

您是否嘗試了以下方法?

expect(page).to have_selector("label[for='landing_zip_code']" && "label.field_with_errors") 
相關問題