By.id or By.cssSelector?
beginner Locators Challenge 1 of 13
The page has two email inputs, both with name="email": a quick login form in the header and a newsletter form in the footer. Write a Selenium locator that returns the newsletter email input.
Requirements
- Use
driver.findElement(By.cssSelector("...")). - Return the input inside the newsletter form, not the login field.
- Do not use
:nth-child/:nth-of-type, and do not pick an element out of afindElementslist.
Expected output
Resolves to the email input inside the footer newsletter form (not the login form's email field).
Checks (3)
- ○Resolves to exactly the intended element(s)
- ○Uses By.cssSelector
- ○Does not rely on position or pick from a list
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 greenView page HTML
<header class="site-header">
<form id="login-form" class="inline-login" action="/session">
<input id="email" name="email" type="email" placeholder="Email">
<input id="password" name="password" type="password" placeholder="Password">
<button type="submit">Log in</button>
</form>
</header>
<main>
<h1>QA Weekly</h1>
<p>Practical testing tips, every Friday.</p>
</main>
<footer class="site-footer">
<form class="newsletter" action="/subscribe">
<h2>Get the newsletter</h2>
<input name="email" type="email" placeholder="you@example.com">
<button type="submit">Subscribe</button>
</form>
<p class="legal">Questions? hello@example.test</p>
</footer>