Site icon Learn Automation

Complete Guide of Selenium Basics and Environment Setup

Complete Guide of Selenium Basics

In this post, we will give you complete guide of Selenium basics knowledge like What is Selenium, What is WebDriver, Exploring Selenium API, Environment Setup for Selenium, automation examples, Locators and how to use locators in Selenium.

What is Selenium?

Selenium is used to automate the browsers.

It is a free open source tool to automate the web based application only across different browsers and platforms. We can use multiple programming languages like Java, C#, PHP, Python, Perl, Ruby in Selenium test scripts.

We cannot test any desktop application and Mobile application.


What is WebDriver?

WebDriver is now an official W3C specification, and it is a method of interacting with a web browser.

Previously, with Selenium RC, Selenium would operate with the browser by injecting JavaScript to interact with the elements.

With the adoption of WebDriver, browser manufacturers like Mozilla, Google and Microsoft edge release their browser with the ability to be controlled by a hook that Selenium can tap into.

This hook enables Selenium to interact with web-browser in the same way that humans do.

There are multiple programming languages which are supported by WebDriver such as Java, PHP, Ruby, Python, .Net to create test scripts.

It also supports multiple operating system like Microsoft Windows, Linux and Apple OS.

Complete Guide of Selenium Basics:

Selenium API: 

To explore an API for selenium we need to have a setup.

Eclipse any version is Ok. [Download Eclipse]

Java should be installed.

Selenium jar downloaded from


Steps to open API just to explore:

Create Java project with name selenium-api , then create a simple Java class with a main method. See below screen.

Add the jar files of selenium to this project.

Steps to add jars:

Right click project > go to Build path > Configure build path > libraries > Click add external jars > browse selenium jars from your system.

You can read this post in details [How to Add External jars in Eclipse]

Click on Apply and Close.

Once it is added project is look like this.


Now we will start writing selenium code inside main method.

By using Ctrl + space shortcut for auto complete of any existing class names/methods.

In our case write ‘Web’ and Ctrl + space key and select Interface name.

While writing WebDriver observe package name, it is coming from as highlighted org.openqa.selenium. This is from selenium jar which we just added.

Now if we try to see the source of WebDriver we may see below screen.

Right click on WebDriver and click on Open declaration or press F3. See in below image.



After click on attach source we can browse the source file. After browse src file or jar file we can see the source code of any API.

Remember, we use byte code always for execution, but to explore more we need to read API, so we did above process.

Below some important selenium interfaces we need to look at –


WebDriver is an interface in java having various methods. It drives the browser directly.

Do Ctrl + O, you will see all methods there or go to outline window.

WebDriver Interface’s Methods:


WebElement Interface’s Methods:

Locators in Selenium:

Selenium uses locators to find the web elements of your webpages that it needs to interact with. There are eight locators we can use in selenium.


How to use locators in Selenium?

Many locators are there in Selenium.


Id to Select the Element with a specified @Id attributes.

It is a unique reference to a web element which is set by developer while writing the code.




It is preferable to have a unique id, so it unlikely to meet similar values.


Feasible for elements with fixed IDs but not for the generated ones.


Name to Select the First Element with the specified @Name attributes.

Every form has input fields with unique names. Most of the time, names are unique, but it’s not a restriction.




It is more appropriate to use it when you are using similar types of elements on web page.


Using it with a dynamically generated list is tough.

Link Text

Link text to select the Link element which contains the matching text.

It is a perfect way to find the links on a page.




It will only work for anchor tags.

Use it for checking navigation flows.


You need to provide the link text for it to work.

Partial Link Text

Partial Link Text to Select Link element which contains text matching the specified partial Link text.

It is almost similar to the previous locator.




It is good if link name is very long.


As we do write complete link, it may conflict with other links will be duplicated.


These are tag name of html.

If we want to know list of all tags and size, then this is easy to get by this locator.

FindElements need to be used as there may be many tags of the same name.

This method will return a list of WebElements, later we can iterate that list.



CSS Selector:

CSS Selector to access the elements.

CSS Selectors are no different that the Xpath. But they are powerful.

Unlike the Xpath, these are not dependent on DOM structure.

These are helpful to find the webelements which is difficult to do with xpath.




Relatively faster than Xpath.

Its usage is growing as the web page are getting more style-centric.

It’s easy to define a unique CSS locator as you can combine multiple CSS attributes.


It’s not a easy to form a Css Selector and requires a deeper understanding of the CSS/javaScript.


Xpath is a xml path in xml document to track an element.

Xpath is a good way for walking through the DOM structure of the web page.

Xpath locators are robust and reliable.

While using this you should be very careful while forming an Xpath as it may not work if there are changes in the web application.


//tagName[@attributes Name=’value’]

Xpath is divided into two parts.

 1. Absolute XPATH: It starts from the root element within the web page or part of the page and goes to identify the target web element.



2. Relative XPATH: The relative Xpath is easy to manage as those are short and concise.

It is also better than the previous xpath style as it may survive the changes in the page HTML.

Though, building a relative xpath is time consuming and quite difficult as you need to check all the nodes to form the path.

It starts with double slash (//)




In coming post we will see How to handle dynamic Xpath in Selenium.

Must Read:

 How To Select Multiple Checkbox in Selenium


In this post, we have covered ‘Complete Guide of Selenium Basics, Envrionment setup for Selenium, Different types of locators and how to use it.

We have also learnt pros and cons of all locators.

I am sure this content added some additional value in your skills and also helpful to start selenium from scratch.

Final word, Bookmark this post Complete Guide of Selenium Basics  for future reference.

If you have other questions or feedback, the comment section is yours. Don’t forget to leave a comment below!

Also Read Below Post:

How To Resolve Element Not Interactable Exception



Exit mobile version