Using XPath in Web Application Testing (Selenium)

Using XPath in Web Application Testing (Selenium)

With Selenium making waves in Web Application testing and more testers are taking to it like duck to water. Let’s discuss the importance of using XPath for Automation Testing using Selenium.

On a web page, there are numerous objects catering to varied functionality. Every object has a distinct ID and functionality associated with it. However, when we want to carry out Automation Testing without using the typical record and playback; it becomes necessary that we should be aware of all the objects that are within our preview. This means that unless we have information about the object in consideration, it will NOT be possible to have code written for addressing the object needs.

The concept of XPath comes about when identifying these objects on the web page. As I mentioned earlier, every object has a distinct ID and functionality associated with it. It is this XPath which is traced, tracked and put to use in order to aid us in writing an effective automation code.

Let’s find out the means to identify the XPath for each object.

1) First, we need to download the FireFox Addon called “FireBug” and install it.

Firebug integrates with Firefox to provide us a lot of information at our disposal at the time of browsing. We can get information about CSS, HTML, JavaScript and other attributes in any webpage.

Download FireBug
Download FireBug

 

 

 

 

Add FireBug to your Firefox
Add FireBug to your Firefox

 

 

 

 

Activate FireBug
Activate FireBug

 

 

 
2) Next, download the Addon “FirePath” and install

FirePath is a Firebug extension that adds a development tool to edit, inspect and generate XPath expressions and CSS3 Selectors.

Download FirePath
Download FirePath

 

 

 

Initiating object in FirePath
Initiating object in FirePath

 

 

 

 

 

 

Separate FirePath tab in FireBug window
Separate FirePath tab in FireBug window

 

 

 

 

3) FirePath installed.

Once FirePath is installed, we will get a new tab within the FireBug window. This is where the details on XPath are captured.

XPath traced
XPath traced

 

 

 

 

 
Things you can do with FirePath

  • Edit XPath expressions and CSS3 selectors with auto completion for XPath (using TAB or up and down arrows).
  • Evaluate the expression on HTML or any XML documents.
  • Display the result of evaluations in a Firebug-like DOM tree.
  • Highlight the results directly on the document displayed by Firefox (works only with HTML documents).
  • Generate an XPath expression or a CSS selector for an element by right clicking on it and selecting “Inspect in FirePath” in the context menu.\
  • Define the evaluation context of an XPath expression or CSS3 selector.
  • Choose the document in which to evaluate the XPath expression or CSS3 selector (only applicable for HTML documents with frames or iframes).

Happy XPath-ing!!!

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s