Search

Monday, 7 March 2011

Selenium IDE: the way to test the locators

Selenium IDE is quite restricted solution and it's not recommended to use it as a solution for full scale test automation. But there're some areas where it helps a lot. Of course it can record sample tests and convert it into the code. That's the main Selenium IDE feature. But not the only one. Selenium IDE is very helpful when we want to test our locators and make sure they point to proper element. In this post I'll try to make step by step instructions how to do that.

OK. Let's open some page in Firefox first. In our example we'll take Google start page.

After we open start page we can open Selenium IDE. I prefer to open it as side panel. It can be done by View > Side Panel > Selenium IDE menu item selection. After all you can have a view like that:

Now we can try Selenium IDE to locate the element. Let's try to locate the highlighted text field from the above image.

The name of this element is "q". So we can use any locator types, e.g.:
  • q
  • name=q
  • css=input[name=q]
  • xpath=//input[@name='q']
How to check whether locator is correct? In Selenium IDE table click on the first empty row. This should enable editor text fields. Selenium IDE will look like:
After that you can enter any of the locators mentioned before into the text field located to the left from Find button. When you click on Find button and locator entered is proper the corresponding UI element will be highlighted with green. It should look like:
Good. We've found the way how we can visually determine whether locator is proper. Last thing here is to see how Selenium IDE behaves whether locator is incorrect. It should show the screen like:

In the Log section you'll see the error message.

No comments:

Post a Comment