Bird
0
0

Which of the following Selenium Java code snippets correctly inputs the text "banana" into an auto-complete field with id "fruitInput"?

easy📝 Syntax Q3 of 15
Selenium Java - Handling Form Elements
Which of the following Selenium Java code snippets correctly inputs the text "banana" into an auto-complete field with id "fruitInput"?
Adriver.findElement(By.id("fruitInput")).sendKeys("banana");
Bdriver.findElement(By.name("fruitInput")).sendKeys("banana");
Cdriver.findElement(By.className("fruitInput")).sendKeys("banana");
Ddriver.findElement(By.tagName("input")).sendKeys("banana");
Step-by-Step Solution
Solution:
  1. Step 1: Locate element by id

    The question specifies the field has id "fruitInput", so By.id is the correct locator.
  2. Step 2: Use sendKeys to input text

    sendKeys("banana") inputs the string into the field.
  3. Final Answer:

    driver.findElement(By.id("fruitInput")).sendKeys("banana"); -> Option A
  4. Quick Check:

    Id locator is most precise for unique elements [OK]
Quick Trick: Use By.id for unique input fields [OK]
Common Mistakes:
MISTAKES
  • Using By.name when id is specified
  • Using By.className which may not be unique
  • Using By.tagName which is too generic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes