In previous two posts I have explained how to setup a sample web application, recording and playing back tests with Selenium IDE. Now, we will understand how Selenium identifies the objects on the Application Under Test.
To identify the objects such as Links, Buttons, Edit boxes, Drop downs, etc on the application Selenium uses a concept called “Locators”. There are around 8 different types of locators. Out of them, I will be explaining only four as they are widely used while automating the test cases using Selenium.
- id = id – By default Selenium IDE takes “id” as Locator
Every Web Page will be having some HTML Source code. This can be viewed using “View –> Page Source / View source” on the browser. In the following picture we can see “id” attribute of a HTML tag is used as a locator to identify an object.
2. name = name (Second locator)
We will do the following steps to understand how exactly Selenium identifies the objects:
- Start Selenium IDE from Tools menu of the browser
- Login to sample application – Sugar CRM
- Click on Accounts tab
- Click on Create Account link
- Now Create Account Page gets displayed
Selenium IDE has recorded all these steps. In the following pictures all the steps above can be seen.
In the following picture we can see the “name” property of the object is used as Locator to identify the object.
3. xpath = xpathExpression. Xpath is used as a Locator to identify an object. This is an expression which is formed by combining various HTML tags. For example: //a[contains(text(),’VRL travels’)], //div[@id=’shortcuts’]/span/span/a/span
4. link=link text (in HTML source we can located this using “href” tag)
I hope you have understood how Selenium identifies objects using different Locators with all of the above screenshots & explanation.
Please provide me your valuable suggestions through comments.