Skip to content
SDETRole
SDETRole

Exact versus substring text

beginner Locators Challenge 4 of 22

After a document is saved, the toolbar shows the status text Saved. Write a locator for that status text only.

Requirements

  • Use page.getByText(...).
  • Resolve to exactly one element. “Saved drafts”, “unsaved changes” and “saved automatically” must not match.
  • Do not use .nth(), .first() or .last().

Expected output

Resolves to exactly 1 element: the "Saved" status text in the editor toolbar.

Checks (3)

  • ○Resolves to exactly the intended element(s)
  • ○Uses getByText
  • ○Does not rely on position (nth, first or last)
example.spec.tsLocator engine · not a real Playwright run

Ctrl/⌘ + Enter to check locator · your code is saved in this browser

Results

Check your locator to see which elements it resolves to.

Page under test

matches are outlined in green
View page HTML
<div class="editor">
  <header class="toolbar">
    <button type="button">Save</button>
    <button type="button">Save as draft</button>
    <span class="status">Saved</span>
  </header>
  <aside class="drafts">
    <h2>Saved drafts</h2>
    <ul>
      <li>Release notes (unsaved changes)</li>
      <li>Q3 regression plan</li>
    </ul>
  </aside>
  <article>
    <h1>Sprint 42 test summary</h1>
    <p>All changes are saved automatically every 30 seconds.</p>
  </article>
</div>

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →