Bird
0
0

Which of the following is the correct syntax to select a date element by XPath in Selenium Java?

easy📝 Syntax Q3 of 15
Selenium Java - Handling Form Elements
Which of the following is the correct syntax to select a date element by XPath in Selenium Java?
Adriver.findElement(By.id("//td[@data-date='2024-06-15']")).click();
Bdriver.findElement(By.xpath("td[data-date='2024-06-15']")).click();
Cdriver.findElement(By.cssSelector("//td[@data-date='2024-06-15']")).click();
Ddriver.findElement(By.xpath("//td[@data-date='2024-06-15']")).click();
Step-by-Step Solution
Solution:
  1. Step 1: Understand XPath syntax

    XPath uses double slashes and attribute filters like //tag[@attr='value'].
  2. Step 2: Match correct Selenium locator syntax

    By.xpath requires a valid XPath string; driver.findElement(By.xpath("//td[@data-date='2024-06-15']")).click(); matches correct XPath syntax.
  3. Final Answer:

    driver.findElement(By.xpath("//td[@data-date='2024-06-15']")).click(); -> Option D
  4. Quick Check:

    Correct XPath syntax = driver.findElement(By.xpath("//td[@data-date='2024-06-15']")).click(); [OK]
Quick Trick: XPath uses //tag[@attr='value'] format [OK]
Common Mistakes:
  • Using CSS selector syntax inside By.xpath
  • Missing double slashes in XPath
  • Using id locator with XPath string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes