</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What is the difference between single slash (/) and double slash (//) in XPath?

Single slash (/) creates absolute XPath from root; double slash (//) creates relative XPath from anywhere in DOM.

Answer

SyntaxTypeDescriptionExample
/ (Single Slash)Absolute XPathSelects from root node only. Every intermediate node must be specified.html/body/div/input
// (Double Slash)Relative XPathSelects matching nodes anywhere in the document.//input[@id=''user'']

Single Slash Example:

XPATH
html/body/div[1]/form/input

Must start from html root — very rigid.

Double Slash Example:

XPATH
//form/input

Finds any form > input combo anywhere in the DOM.

Combined usage:

XPATH
//div[@id=''login'']//input[@type=''text'']

Start relative, then go deeper.

Key Rule: Always prefer // in automation — makes tests resilient to DOM changes.

Follow AutomateQA

Related Topics