Skip to content
SDETRole
SDETRole

Count the organic search results

beginner findElements Challenge 4 of 13

The search page says “4 results”. Write a locator that returns all the organic result items, so a test can assert that there are exactly four.

Requirements

  • Use driver.findElements(...).
  • Include only the organic results in #results: not the sponsored result, not the nested sitelinks, not the related searches.
  • The list must contain exactly the 4 organic li elements.

Expected output

Resolves to the 4 organic result items, so `.size()` is 4.

Checks (3)

  • ○Resolves to exactly the intended element(s)
  • ○Uses findElements to collect every match
  • ○Uses a precise CSS or XPath selector
Solution.javaLocator 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
<main class="search-page">
  <h1>Search results for "login"</h1>
  <p class="meta">4 results</p>
  <ul id="results">
    <li class="result sponsored">
      <a href="/ad/loginpro">Try LoginPro free</a>
      <span class="label">Sponsored</span>
    </li>
    <li class="result">
      <a href="/docs/login">Login page test cases</a>
      <ul class="sitelinks">
        <li><a href="/docs/login#negative">Negative cases</a></li>
        <li><a href="/docs/login#sso">Single sign-on</a></li>
      </ul>
    </li>
    <li class="result"><a href="/blog/auth">Testing authentication flows</a></li>
    <li class="result"><a href="/q/123">Why does my login test flake?</a></li>
    <li class="result"><a href="/tools/jwt">JWT decoder</a></li>
  </ul>
  <h2>Related searches</h2>
  <ul class="related">
    <li><a href="/search?q=login+selenium">login selenium</a></li>
    <li><a href="/search?q=login+playwright">login playwright</a></li>
  </ul>
</main>

Type to search across SDETRole.

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