how to write relative xpath code example

Example 1: relative xpath sample

//input[@id=’user-message‘]

Example 2: what is relative xpath

Single Slash “/” is used to create XPath with absolute path 
Double Slash “//” is used to create XPath with relative path 
Xpath stands for XML path
-Absolute Xpath: is a direct way to locate an element and
it uses Complete path.

-On the other hand

Relative Xpath: starts from the middle of the
HTML DOM and You can find unique parent node
and simply start from there to element you want. 
Less fragile. Shorter. Never fails to
identify object even though object’s
location changes. It is written directly from
the Web Element using Web Element attribute


Syntax = //tagname[@attribute='value']

Tags:

Html Example