キュウバーとRSpecを使用して、黄色のdiv
がクラスcard-selected
を持っているかどうかを確認しました。Rails Capybara RSpec XPath CSSセレクターは子供を使用しています
私が書いているコードは
node = page.find(:css, '.card-selected')
#<Capybara::Node::Element tag="div" path="//HTML[1]/BODY[1]/DIV[3]/DIV[1]/DIV[2]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/DIV[7]">
である私はChromeでretured XPathをコピーすると、予想通り、私は、黄色のdivを選択し得ます。
問題はノードにCSS属性を問い合わせることで発生します。私が理解したように、これは予想される動作ではありません。私はこの振る舞いから、ノード
# Checking for parent node contents
node.find(:xpath, '..').has_css?('.card-selected')
true
node.find(:xpath, '..').has_css?('.card-deselected')
true
node.find(:xpath, '..').has_css?('.card-contents')
true
の親を照会すると
# Checking for current node contents
node.has_css?('.card-selected')
false
node.has_selector?(:css, '.card-selected')
false
node.has_css?('.card-contents')
true
しかし、has_css?
方法は、子供たちだけの内容をチェックしているようですノード自体ではない。私は、親に問い合わせるとあまりにも複雑になるため、回避策を見つけることができないようです。
私はここで何を理解していませんか?
、node.visible期待
matches_selector?
は何がしたいのですか? trueを返します –