Bird
0
0

Identify the error in this Selenium Java code for multi-page navigation:

medium📝 Debug Q14 of 15
Selenium Java - Page Object Model
Identify the error in this Selenium Java code for multi-page navigation:
driver.get("https://example.com/home");
WebElement link = driver.findElement(By.className("nav-link"));
link.click();
String title = driver.getTitle();
assert title.equals("Home Page");
AMissing driver.quit() after test
BIncorrect assertion method syntax
CUsing className locator without checking multiple matches
DUsing getTitle() instead of getCurrentUrl()
Step-by-Step Solution
Solution:
  1. Step 1: Analyze locator usage

    Using By.className("nav-link") may find multiple elements, causing ambiguity.
  2. Step 2: Check other code parts

    Assertion syntax is correct, driver.quit() is optional, and getTitle() is valid for title check.
  3. Final Answer:

    Using className locator without checking multiple matches -> Option C
  4. Quick Check:

    className may match many elements [OK]
Quick Trick: Ensure locators uniquely identify elements [OK]
Common Mistakes:
MISTAKES
  • Ignoring that className can match multiple elements
  • Thinking getTitle() is wrong for title checks
  • Believing driver.quit() is mandatory in every snippet

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes