在我正在使用的书中,使用此留置权代码进行了测试
assert_select '.store .entry > img', 3
我知道它正在类存储内的类条目内的html中寻找标签。我不知道>是什么意思。实际上,此代码未能通过测试,因为它最终返回的值为0而不是3。但是,如果我删除了>并使用了它
assert_select '.store .entry img', 3
该程序能够找到3个img元素。在这种情况下,“>”符号是什么意思?另外,当书中包含该符号时为什么为什么找不到img标签,而删除该符号却能正常工作呢?
>
表示仅匹配img
属于class元素的直接子元素entry
。这意味着img
将被匹配:
<div class="store">
<div class="entry">
<img src=""/>
</div>
</div>
但不是这个:
<div class="store">
<div class="entry">
<p>
<img src=""/>
</p>
</div>
</div>
当您删除它时,img
将在两个示例中找到元素。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句