| Feature | Absolute XPath | Relative XPath |
|---|---|---|
| Starts from | Root node (html) | Anywhere in DOM (//) |
| Syntax | /html/body/div/input | //input[@id=''user''] |
| Stability | Fragile — breaks on DOM changes | Robust — survives UI changes |
| Length | Long | Short and concise |
| Maintenance | Difficult | Easy |
| Performance | Slower | Faster |
| Recommended | No | Yes |
Absolute XPath:
XPATH
html/body/div[1]/div[2]/form/input[1]
Equivalent Relative XPath:
XPATH
//form//input[@type=''text'']
Golden Rule: Always use Relative XPath in your automation framework.
