Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要检查页面上是否存在特定类型的选择器中的某些内容。例如,假设我有以下 HTML:
<h2>HEADLINE ONE</h2> <h2>HEADLINE TWO</h2>
我知道如何只选择页面上的第一个:
find('h2').should have_content('Headline Two') # have_content is also case insensitive
如何检查h2页面上所有 s 中是否存在内容?
h2
显然,您可以选择具有给定文本的元素:
page.should have_selector('h2', text: /#{headline}/i)
注意:我使用正则表达式使文本搜索不区分大小写。