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.

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.

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

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.