Bird
0
0

Identify the error in this BasePage method and how to fix it:

medium📝 Debug Q14 of 15
Selenium Java - Page Object Model
Identify the error in this BasePage method and how to fix it:
public void enterText(By locator, String text) {
  WebElement element = driver.findElement(locator);
  element.sendKeys();
}
AsendKeys() is missing the text argument; fix by adding sendKeys(text)
BfindElement should be replaced with findElements
CMethod should return boolean indicating success
DLocator type By is incorrect; use String instead
Step-by-Step Solution
Solution:
  1. Step 1: Check sendKeys usage

    The sendKeys method requires a String argument to input text.
  2. Step 2: Fix the method call

    Change element.sendKeys(); to element.sendKeys(text); to send the provided text.
  3. Final Answer:

    sendKeys() is missing the text argument; fix by adding sendKeys(text) -> Option A
  4. Quick Check:

    sendKeys needs text argument [OK]
Quick Trick: sendKeys always needs the text argument [OK]
Common Mistakes:
  • Calling sendKeys without arguments
  • Using findElements instead of findElement for single element
  • Changing locator type incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes