Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara: How to check that an element has content among many similar elements?

I need to check that some content exists on the page within a specific type of selector. For example, let's say I have the following HTML:

<h2>HEADLINE ONE</h2>
<h2>HEADLINE TWO</h2>

I know how to select only the first one on the page:

find('h2').should have_content('Headline Two')  # have_content is also case insensitive

How would I check that the content exists among all of the h2s on the page?

like image 611
Andrew Avatar asked Jul 25 '12 15:07

Andrew


1 Answers

Apparently you can select elements with a given text:

page.should have_selector('h2', text: /#{headline}/i)

Note: I used a regular expression to make the text search case insensitive.

like image 66
Andrew Avatar answered Nov 16 '22 13:11

Andrew