First steps with Selenium Selenium IDE tool
Date posted
10 May 2013
Reading time
18 Minutes
First steps with Selenium Selenium IDE tool
If you would like to learn more about the practical side of test automation, but you are not quite sure where to start Selenium IDE might be the answer. The goal of the following post, which I've structured as a mini-tutorial, is to provide an overview of the basic functions of Selenium IDE, its possibilities and limitations.
Installation
To be able to work with Selenium IDE you will need the Firefox browser. After it is installed, you will need to download the Selenium IDE installer from: http://seleniumhq.org/download/. When Selenium IDE is installed, it is then available as a Firefox plugin.
Test Recording
The easiest way to see what Selenium IDE provides is to use it for the purpose it was created for: to record a test.
We will execute and record a simple test: using Google we will search for kainos.pl page and then open the page and make sure this action was successful.
We need to start Selenium IDE and then press the round red button - this will start recording of our test. Next, in the new window of the Firefox browser we go to www.google.pl and put the phrase that we are going to look for 'kainos.pl' into the search form, and then press the Search button.
When the above steps are executed, we should see search results similar to the ones below:
Let's get back to the Selenium IDE window. You should see the actions we have just performed were saved and also 'translated' into the commands that Selenium IDE is able to understand (Selenium commands are in a language called Selenesse). The Base URL field has also been filled in automatically.
The open command opens the URL address specified with the Target parameter. In this case the value of / means the Base URL address will be used. The type command is then used to type the value specified with the Value parameter into the form field specified with the Target parameter.
More details on the particular Selenesse commands can be found under the Reference tab of Selenium IDE.
Identifying the UI elements
While the value of the type command's Value parameter is rather obvious (it simply specifies the text we want to put into the input field of the searching form), the Target parameter's value is not so obvious.
In case of the methods interacting with the web page elements (such as type or click), the Target parameter identifies the page's element for which the given action should be executed.
In our case we used the id identifier to identify the page's elements. The natural question here is where this value is taken from. To be able to answer it, we will need to take a closer look into the source code of the web page. The Inspect Element option available in the newer versions of Firefox will be extremely helpful here.
Clicking the right mouse button on the search field of the Google page, we choose the Inspect Element option. As the result, the information on the chosen element will be displayed. We will also be able to preview the source code containing the element we clicked.
The text marked with green in the above picture is the id attribute of the form's input field that we have been looking for (the text marked with blue is the value of class attribute). The mentioned attributes can also be found directly in the source code of the page.
Finding elements using the id attribute value is not the only available option the Selenium IDE can handle. What is more, in case of the pages where the id value is generated automatically and differs each time the page is loaded, this way of element identification may be insufficient.
Other popular ways of element identification are:
- name=nameAttributeValue finds the first element with the given name attribute's value (in the case of our form the Target parameter value would be name=q).
- xpath=xPathExpression locates an element using the XPath expression (in our case the XPath expression value could be xpath=//tbody/tr/td/div/input[@name='q']).
- link=textPattern selects the link (anchor) element which contains text matching the specified pattern.
- Open the Google.pl search page
- Fill in the search form input field with the kainos.pl phrase
- Click the Search button