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[2]/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.
Hey Sitaram,
wonderful job man… Thanks for tremendous help
I have interview tomorrow can u help me how to call scripts in selenium and
> – How to execute scripts using various browsers.
I will never forget your help.
Thanks i advance
hi Sir i am gopi new to selenium please help me how i can learn selenium online.
Go to Selenium – page created on this blog.. it is like index.. go through the posts one by one… and do whatever is explained.. I hope you will definitely be able to learn the selenium easily..
Hay Sitaram,
You done a wonderful job and this is very helpful for beginners to understand the Selenium.
The way which you are explaining the topics are simply superb.
Could you pls add some more information into it; like coding using JUnit, TestNG, Ruby and other tools.
Thank you very much,
Murali Krishna
Thanks a lot Murali… trying to update the blog as much as possible…
Hello Sitaram,
Thank U Very Much for Providing this Information.This is most helpful to the selenium beginners .
hi
i’m very new to selenium , so if my doubt is silly please excuse me , in the syntax for xpath what actually the span is, n what is the use of this object identification
raj,
no worries.. let me explain you the xpath. In HTML source we can find lot of html nodes / tags. If you look at the source from top to bottom, and start combining them one after the other to reach a particular element that is xpath. Span is a HTML tag. Both Div and Span are used in html source which are primarily used to different blocks on the web page. You can read further on these tags in http://www.w3schools.com/
I hope this answers your question.
— Seetaram
HI seetharaman,
Is it possible to convert manual test cases to selenium scripts through any framework. Help me that my question is right , im going in a right way. Is it possible to convert manual test cases to selenium test cases in order to reduce human efforts.
Answer to your question is YES!! Selenium will reduce the manual testing effort….
Hi Seetharam,
Your blog is so helpful, I am able to understand very easily. Thankful to you
Regards
Srinivas
Thanks Srinivas…
You find the simplest way to explain it!
Thanks a lot
Hello Sir,
This is Vanitha. Could you pls tell me how to explain the selenium FW in interview…?
Thanking you.
Hello Sir,
This is ramana. I want to learn selenium but i am very poor in java. Is there any effect on me if i dont know that?. Is there any way to quickly learn selenium . I just saw u r website. Its good. I want this concepts little more clearly. R u providing any materials here to learn?
Hi Sitaram,
Your way of explanation and examples are very useful for everyone but i think you forgot to explain object identification using CSS. Selenium is browser independent for that reason everyone would prefer to CSS. If you explain object identification using CSS that is very useful.
And this is my suggestion only.
Thanks,
Surendra
Thanks Surendra.. I will definitely do that…
Hi Ram,
this blog very helpful to me , you explanation good.
Thank you
sir,
pls explan how to config web driver in eclipse and how to execute
how to config selenium grid and how to execute
thank you.
Very helpful blog…..Great job…
Hi Sir
your explanation is very useful to everyone.