โ† Back to libraryQuestion 139 of 273
๐ŸงชSeleniumIntermediate

XPath Concepts

๐Ÿ“– Detailed Explanation:

XPath (XML Path Language) uses expressions to navigate through the HTML document. It is the most flexible locator strategy and the only one that allows 'backward' navigation (finding a parent based on a child). XPath can use text content, attributes, positions, and functions. There are two types: Absolute XPath (starts with single slash `/`) and Relative XPath (starts with double slashes `//`). Advanced XPath uses functions like `contains()`, `starts-with()`, `ends-with()`, `normalize-space()`, and `count()`.

๐ŸŒ Real-World Example:

XPath is like describing a location: '//' means 'anywhere in the document'. '@attribute' means 'find this attribute'. 'contains()' means 'match partially'.

๐ŸŽฏ Scenario-Based Interview Question:

The 'Login' button has no ID, no Name, and the Class is dynamic. How do you find it using XPath?