Managing Locator Builders in Selenium IDE

If you use Selenium, then you must already know about locators. The locators in Selenium are usually the target part of your Selenese commands which identifies the elements on the web page that you want to interact with. This post is not about locators, but about the locators builders.

I introduced the Locator Builders in Selenium IDE through some of my earlier posts. They are components that build the locators for you when you are recording in Selenium IDE. You can take a quick look at Creating CSS Locator Builders for Selenium IDE and The Selenium-IDE 1.x plugin API (Part 12) – Adding Locator Builders. Selenium IDE has several locator builders bundled with it, including the most recent one for building CSS locators. See Welcome Selenium IDE 1.0.11 (with Firefox 4 support) and A Quick Introduction to CSS Locators in Selenium. Selenium IDE plug-ins can also add new Locator Builders.

The order of the Locator Builders can be very important. The result of the first Locator Builder is added to your recorded Selenese command. You have the ability to choose another locator from the target drop down list until you close the recorded test case. When some people get stated with Selenium IDE, posts like Learn Alternate Locators Using Selenium IDE open a whole new world. If you need a particular locator type for your web application or a part of your web application, you have the option of manually changing it from each recorded command. It is simply more efficient to change the order of the locator builders as you need.

Managing the order of the Locator builders was possible, but required the use of Selenium IDE Extensions and JavaScript along with a restart of the Selenium IDE. It was generally a pain if you needed to change it several times. I have been thinking of easing this pain for a while, so when Adam mentioned that this was an area that he wanted improved, I took up the task. The latest version of Selenium IDE (v1.3.0) includes my changes to manage the Locator Builder order. Now you can simply open the Options dialog and select the Locator Builders tab to manage the order. You can drag and drop the locator builders to the order you want and click the OK button. Your preferred order will be applied instantly for all new recorded commands. No more messing with JavaScript or restarting the IDE. Your preference will also be saved and remembered across sessions.

At the first look, the management of Locator Builders lacks a few features, but there was a concious decision for most of them. Firstly, it is not possible to remove a locator builder. I decided that deleting a locator builder was generally a bad idea. Instead of deleting a Locator Builder, it is better to change the order and move it down. This way, it is out of the way and you can still have it back in case you change your mind some day. Secondly, once any Selenium IDE plug-in provides a Locator Builder, its order will be remembered even if you remove the plug-in. I made the decision to retain the removed locator builder because it is quite nice to reinstall the plug-in and have the old order back. I have come across some cases when you need to uninstall some plug-in and install it again. Lastly, there is no way to enable or disable a Locator Builder. Again, I decided against having this feature as changing the order is usually sufficient.

There would be some more enhancements coming up in the future. I am planning to add a way to identify the Locator Builders which are not currently available. Another enhancement would be to give a short description and some examples of the kind of locators that are built by the locator builder. Let me know if you can think of anything else.

In the past some people have mentioned to me that they enjoy reading about my experiences as I develop these features. I found working on this enhancement quite nice. I recently started down the Functional Programming road and I used some of these concepts in the code. It was quite satisfying to see the amount of code I had to write shrink down. Most of the time, I wrote two version of the same piece of code and kept the one I thought was better. For people who have no exposure to functional programming might initially find some parts of the code a bit hard to read, but I hope I have put in the right balance between readability and ease of programming. The major part of my time was spent in deciphering how to use drag and drop in a Listbox to rearrange the items. I think I have done a pretty good job and I have a reusable module that can save some people some time. I hope to write a blog post on it and make it available as soon as I find some time.

Don’t hesitate to leave a comment about what you think. I always love hearing from you.

This entry was posted in Selenium IDE and tagged , , , , , , , , , . Bookmark the permalink.

9 Responses to Managing Locator Builders in Selenium IDE

  1. Prasad says:

    Th x for your valuable plugins

    How to use Power Debugger Plugins Can you guide

  2. Pingback: A Smattering of Selenium #63 « Official Selenium Blog

  3. Pingback: Selenium IDE v1.3.0 Released and Includes Firefox 7 Support | Really Simple Thoughts of a Perpetual Learner

  4. Stephen Friedrich says:

    Great little time saving feature!
    Now I can move my custom locator builder for ExtJS to the top.

    If only there would be a way to have the IDE accept locators that evaluate to a different DOM element.
    For example if the user clicks an ExtJS button (rendered as a table) and happens to click on the top right border, then the best I can currently do is to return “#my-button-id .x-btn-tr i”.
    A much better locator would be just “#my-button-id”, but Se does not accept that :-(

    • Samit Badle says:

      Hi Stephen,

      I am glad you like this feature. If you are open to hacking your own build of Selenium IDE, perhaps you relax the check that prevents your better locators from working.

      I think this is a valid use case so you can also open a feature request on the Selenium Google Code issue tracker and also open a new thread on the developer discussion group. Once we discuss with the other interested parties, I can implement it in Selenium IDE.


  5. Alex says:

    Samit –

    I think it would be useful to be able to delete unavailable Locators and to reset the LocatorBuilders ordering to the default.

    Deleting LocatorBuilders is useful for me b/c as I have been creating custom Locators I have replaced and renamed some I have made but there is no easy way to cleanup the list.

    Resetting the list / ordering would be helpful as I put together documentation for QAers on how to setup the IDE to work well for specific sites.

    (I opened Issue 2983 before I found this blog)

    Thanks for all your work making such a useful additions!


  6. Suman says:

    Hi Samit,

    I have created a my own user extension for selenium IDE to add one more locator. Kindly see the extension code below

    LocatorBuilders.add(‘zk_component_prefix’, function(e) {
    if (e.hasAttribute(‘zk_component_prefix’)) {
    if (e.getAttribute(‘zk_component_prefix’)) {
    return ‘//’ + e.nodeName + ‘[@zk_component_prefix=\” +
    e.getAttribute(“zk_component_prefix”) + ‘\’]’;
    return null;


    I have added this locator in selenium IDE and put this on top the order, so that it will be used in default.

    I modified my application such that each widget will have this attribute.

    I have restarted my selenium IDE and recorded the test case. But still my new locator is not being used. It still using deafult locator i.e. id

    I am using : Selenium IDE 1.5.0
    Firefox 9.0.1
    I am testing application which is built on ZK framework

    Kindly provide your suggestions in this regard.


    • Samit Badle says:

      Hi Suman,

      After you record a test, can you see your locator in the target field dropdown? There could be an exception being thrown in your code that prevents the locator builder from working. Another thing that can go wrong is that the generated locator may not be valid. This means that if the generated locator does not find the exact same element, it will be ignored. Hope that helps.


Leave a Reply

Your email address will not be published. Required fields are marked *