Sunday, March 27, 2016

Selenium WebDriver: Tools to identify Locators easily



When automating a web application, the most important and time taking task is to come up with unique locators for the elements present on the web page. Once you find out the correct locator, the rest of the automation is relatively easier.
Finding correct and unique locators require human intelligence and below tools can help you in a great deal when you start creating your scripts. Every automation engineer should have these tools in their arsenal.

List of Tools to identify Locators

Firebug  (Firefox addon)
The favourite tool of web developers. Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page. Its console window and inspection tool are the best available in the market.

Firefinder for Firebug
This tool is simple, provide any XPath or CSS selector and it will highlight the matching elements on the web. Simple, lightweight and easy to use. Install it on top of Firebug.

FirePath for Firebug
Right Click on any element and select "Inspect in Firepath", this addon will generate the XPath or CSS selector for you. It also highlights the element on the web page and in the DOM. Very useful. Again install it on top of Firebug.

WebDriver Element Locator (Firefox addon)
This addon will generate XPath for any given element. But the best thing is, it will also generate WebDriver statements for you and also in the language of your choice. Currently, it supports C#, Java, Python and Ruby.  Just right-click on any element and generate the code in your favourite language. It is that simple. The only downside is that it only generates XPath.

Selector Detector (Bookmarklet)
Sometimes XPath and CSS Selectors do not work in a given situation. That's where JQuery selector comes in handy. This is a bookmarklet created by Jessie A. Morris and it will generate the jQuery selector for your on the clicked element. Go to this link and drag the provided bookmarklet to your bookmarks bar. The button will appear with the name Selector Detector. Now click on it and Click on any element and it will generate the jQuery selector for you.

SelectorGadget (Bookmarklet and Chrome Extension)
This tool is created by Andrew Cantino and Kyle Maxwell. It can generate CSS Selectors for you. Authors describe the method to generate CSS selector like this.
Click on a page element that you would like your selector to match (it will turn green). SelectorGadget will then generate a minimal CSS selector for that element, and will highlight (yellow) everything that is matched by the selector. Now click on a highlighted element to remove it from the selector (red), or click on an unhighlighted element to add it to the selector. Through this process of selection and rejection, SelectorGadget helps you come up with the Perfect CSS selector for your needs.
See the video on the provided link to better understand this tool.

SWD Page Recorder (.Net Application)
This is a comprehensive tool and it is more than just a generator. It is developed by Dmitry Zhariy. Using this tool, you can generate selectors as well as full classes for your code in Selenium WebDriver. It allows you to generate Page Object Models for your automation code. If you are a C# developer, this tool will save you ample amount of time. The best thing about this tool that you can write C# code in this tool and see the live results on the browser. That is amazing.

Looking Glass (Java Application)
Although not as comprehensive as SWD Page Recorder, This tool is still useful in finding elements. It also allows you to write groovy scripts and see the results live on the browser. Good for Java developers.

These were some of the tools to identify locators easily. I hope the above list helps the automation engineers in saving their time to identify and verify element locators. I am also working on an application inspired by Looking Glass and SWD page recorder. It will allow you to verify your locators and generate C# classes for you. I am calling it "SeleniumVerify". It is present on GitHub. Currently it is under development and I will soon update you when it is ready for download.
Do you happen to know any other tools. Please share in comment and also give your feedback on this article.

9 comments:

  1. Thanks for your post; selenium is most trusted automation tool to validate web application and browser. This tool provides precise and complete information about a software application or environment. Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium training institute in Chennai

    ReplyDelete
  2. There is another player in the block, called LeanFT for Selenium, that is doing much more than just Locators identification, or easily creating the unique identification code for you.
    If you didn't hear about LeanFT yet and want to learn how it boost the ROI you get from Selenium, this blog will be just for you: https://community.hpe.com/t5/All-About-the-Apps/Using-Selenium-for-Web-Automation-Let-UFT-Pro-LeanFT-help-you/ba-p/6932523#.WKI5UVUrK0k

    ReplyDelete
  3. I have read your blog its very Interesting. Thanks for sharing. Call for low cost ERP software. ERP in Chennai | ERP Software in Chennai

    ReplyDelete
  4. Thank you for this valuable information. I have got some important suggestions from it. I'm working in Brave Technologies Private Limited. We provides lowest price of ERP Software for our clients. Contact us on info@bravetechnologies.in. ERP Providers in Chennai

    ReplyDelete
  5. Really, these quotes are the holistic approach toward mindfulness. In fact, all of your posts are. Proudly saying I’m getting fruitfulness out of what you write and share. Thank you so much
    Digital marketing course in chennai

    ReplyDelete
  6. Thanks for the useful post. Keep posting more like this.
    Webdesign L├╝denscheid

    ReplyDelete
  7. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete