Bird
0
0

Which of the following is the correct syntax to find a checkbox by its name attribute "acceptTerms" in Selenium Java?

easy📝 locator Q3 of 15
Selenium Java - Handling Form Elements
Which of the following is the correct syntax to find a checkbox by its name attribute "acceptTerms" in Selenium Java?
Adriver.findElement(By.className("acceptTerms"));
Bdriver.findElement(By.id("acceptTerms"));
Cdriver.findElement(By.name("acceptTerms"));
Ddriver.findElement(By.tagName("acceptTerms"));
Step-by-Step Solution
Solution:
  1. Step 1: Identify locator type for attribute 'name'

    To find an element by its name attribute, use By.name().
  2. Step 2: Match syntax

    The correct syntax is driver.findElement(By.name("acceptTerms"));.
  3. Final Answer:

    driver.findElement(By.name("acceptTerms")); -> Option C
  4. Quick Check:

    Find by name = By.name() [OK]
Quick Trick: Use By.name() to locate elements by name attribute [OK]
Common Mistakes:
  • Using By.id() when attribute is name
  • Using By.className() incorrectly
  • Using By.tagName() with attribute value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes