</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What is an absolute XPath?

Absolute XPath starts from the root HTML node and traverses the entire DOM to reach the target element.

Answer

An Absolute XPath starts from the root node (html) of the HTML document and traverses the full DOM tree down to the target element.

Syntax: Uses single forward slash /
XPATH
html/body/div/div[2]/div/form/input[1]

Disadvantages:

  • Very fragile — any DOM change breaks it
  • Long and hard to read/maintain
  • Slower to execute (traverses entire document from root)
  • Adding/removing one element breaks the entire path

When to avoid: Never commit absolute XPaths to automation code. Use only for quick one-time debugging.

Comparison:

Absolute XPathRelative XPath
Starts fromRoot (html)Anywhere (//)
StabilityFragileRobust
LengthLongShort
MaintenanceHighLow

Golden Rule: Always prefer Relative XPath in automation frameworks.

Follow AutomateQA

Related Topics