XPath
Use XPath expressions to navigate and select elements within the XML or HTML document.
XPath is a powerful selector type that allows you to navigate the DOM using a path-like syntax. Unlike CSS, XPath supports more advanced queries such as traversing up the DOM, selecting elements based on partial text, and targeting based on multiple conditions. XPath is useful when CSS selectors are insufficient or too limiting, but they can be more verbose and harder to maintain.
Examples:
//button[@id="submit-button"]
//div[contains(@class, "product-card")]
//ul/li[1]
//label[text()="Email"]/following-sibling::input
Last updated