Absolute path Vs Relative path

An  Absolute path is the Full path that points to the a location on one file system regardless of the present working directory .

An absolute path always starts with the root element (/) and the complete directory list required to locate the file.

In selenium for example, /home/example/myReport.doc is an absolute path, which is enough in itself to locate a file in the directory . It does not need any current path location to locate the file . All of the information needed to locate the file is contained in the path string.



Relative path is one which is relative to the current working directory of the user or application .

Relative path starts from current path (//)

A relative path needs to be combined with current path (base path) in order to access a file.
For example, //myReport.doc is a relative path , which is dependent on the current path (/home/example) to be located . Without current path, we can not use relative path alone to locate a file in the directory.


Points to Remember 

                     /    Root
                     .    Current - Using "." makes the path Relative
                    //   Anywhere

Examples 


                    Absolute xPath


                     /html/body/div[1]/form/div[2]/input[id='btnLogin']


                    Relative xPath :


                    .//a[text()='Example text']