Then I should see text matching "text pattern" in the "element" element

This step asserts that the text content of a specific element matches a given regular expression pattern. It locates the element using a CSS selector, waits up to five seconds for it to appear, reads its visible text via the internal getLocatorText helper, and then applies the pattern as a JavaScript RegExp.

The element is identified by a CSS selector string - you can use #id, .class, tag names, or attribute selectors. The pattern is applied with new RegExp(pattern), so it is case-sensitive by default and supports all standard JavaScript regex syntax. This step is useful when a field shows values that vary between environments (such as prices, dates, or generated IDs) and you want to validate the format rather than the exact value. Both I and we are accepted as the subject.

Accepted phrasings

Then I should see text matching "pattern" in the "selector" element
Then we should see text matching "pattern" in the "selector" element
And I should see text matching "pattern" in the "selector" element
And we should see text matching "pattern" in "selector" element

Examples

Then I should see text matching "d{4}" in the "#year" element
Then I should see text matching "$d+.d{2}" in the "#price" element
Then we should see text matching "^[A-Z][a-z]+ [A-Z][a-z]+$" in the "#full-name" element
And I should see text matching "Active|Pending" in the ".status-badge" element

In a real scenario

Scenario: Check that the flood control settings page shows expected window values
  Given I am a logged in user with the "webmaster" user
   When I go to "/admin/config/people/flood-control"
    And wait
   Then I should see "Flood control"
    And I should see "1 hour" in the "#edit-ip-window" element
    And I should see "6 hours" in the "#edit-user-window" element

Related steps

Back to Assertion Steps