Friday, June 9, 2017

WebDriver - Find XPath

WebDriver - Find XPath


In this post we will first see how to install Firebug and later a simple example of how to use Firebug in order to find XPath.

Download and install Firebug. Its a Firefox Add-in.

Launch Firefox. Go to Tools (menu) -> Web Developer -> Get More Tools. WebDriver Find XPath

Web Developer's Toolbox page opens and install the Firebug add-on. WebDriver Find XPath

Now as the Firebug is installed, lets see a simple example of its usage to find the XPath.

Lets suppose we have this table. You can also see below the HTML code of the table.
WebDriver Find XPath
WebDriver Find XPath

Right-click on the element, for example if we need to find element 3 in the table, right-click on it and select Inspect Element with Firebug. WebDriver Find XPath

It shows the element as HTML code as can be seen below. Right-click on it and select Copy XPath.
WebDriver Find XPath
The XPath which is copied above is:
WebDriver Find XPath

The same XPath is being used in this code to find an element and printing its text on the console.
WebDriver Find XPath
WebDriver Find XPath