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.
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.
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.
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).