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 XPath | Relative XPath | |
|---|---|---|
| Starts from | Root (html) | Anywhere (//) |
| Stability | Fragile | Robust |
| Length | Long | Short |
| Maintenance | High | Low |
Golden Rule: Always prefer Relative XPath in automation frameworks.
