Top xpath loactors

Technical
Medium
Infosys
141K views

Question about XPath locators used in test automation.

Why Interviewers Ask This

XPath is a critical tool for locating elements in web automation. The interviewer wants to assess the candidate's proficiency in writing efficient and reliable selectors for testing.

How to Answer This Question

List common XPath strategies like by ID, name, text, and axis-based navigation. Explain the difference between absolute and relative XPath. Recommend using relative XPath for better stability. Mention best practices for avoiding brittle locators.

Key Points to Cover

  • Attribute-based locators
  • Relative XPath
  • Axis navigation
  • Best practices

Sample Answer

Top XPath locators include using attributes like id, name, and class, as well as text content. Relative XPath expressions, such as //div[@id='login'] or //button[text()='Submit'], are preferred over absolute paths for stability. Axis-based locators like ancestor, following-sibling, and preceding allow navigation through the DOM tree. I always avoid relying solely on index numbers or complex nested paths to ensure tests remain robust against UI changes.

Common Mistakes to Avoid

  • Using absolute paths
  • Relying on indexes
  • Ignoring dynamic IDs

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 78 Technical questionsBrowse all 65 Infosys questions