- Selenium Webdriver
- Install java in windows
- Eclipse download
- Selenium Injection
- Java
- Selenium Basic
- Inspect Element
- Selenium Locators
- chropath
Introduction:
Selenium WebDriver is an API that allows us to write automated tests for web applications. The automated tests that use Selenium WebDriver are run by using a web browser. In other words, Selenium WebDriver helps us to verify that our application is working as expected when it is used by a real user. Selenium Web Driver Architecture:Selenium Web driver architecture mainly divided into three parts
- Language level bindings
- Selenium Web driver API
- Drivers

- Language Level Bindings : Bindings refer to the language level bindings with which we can implement the Selenium Webdriver code. In simple words, these are the languages in which we can make a framework, which will interact with the Selenium Webdriver and work on various browsers and other devices. So we have a common API that has a common set of commands and we have various bindings for the different languages. Some Language level Bindings are Java, Java, Python, Ruby, there’s also some other bindings and new bindings can be added very easily.
- Selenium Webdriver API: Selenium Webdriver API sends the commands taken from language level bindings interpret it and sent it to the Respective driver. In basic term, it contains set of a common library which allows sending a command to respective drivers.
- Drivers: Drivers refer to various internet browsers such as IE driver, a Firefox, Chrome, and other drivers such as HTML unit which is an interesting one. It works in a headless mode which makes text execution faster. It also contains mobile specific drivers as well. So the Chrome driver knows how to handle the low-level details of Chrome browser and drive it to do things like clicking the button, going into pages, getting data from the browser itself, the same thing for Firefox, IE, and so on.
Install java in windows
- Visit the Java website and download the installer
- To install Java, you first need to download the installer program from Oracle. Follow the link mentioned below:
- install java in windows
- Navigate to Java SE Development Kit 8u211 as depicted in Image Below

- Click on Accept License Agreement
- Click on the Installer jdk-8u211-windows-x64.exe have selected it as we would be installing it on a 64-bit machine.
- It will land you to Oracle Account Sign In Page

- In case you don't have an account you can sign up by clicking on Create Account
- Fill in all Details as desired and it will Create a New Account

- Post that you can log in and Installer will Install jdk-8u211-windows-x64.exe for your Machine.
- Double click on that and it will Install Java on your Machine post clicking on Next Next buttons.
- Steps for Validation that java is Installed on your Machine
- Open Command Prompt(cmd)
- and type java -version

- Congratulations now you have successfully Installed Java on your Machine.
Eclipse download for windows 10 64 bit
- Download Eclipse Ide which we would be using for Selenium Implementation. Click the link mentioned below:
- eclipse download for windows 10 64 bit

- Click on Eclipse IDE for Java EE Developers.

- Download depending on the bit size of your system.

- Once it completes download right Click on the .zip file and extracts it.
- After extraction Double click on the Eclipse Icon.

- It will ask for the workspace location by default it creates the workspace in Documents you can change it as desired.

- Click OK. Before installing eclipse ensure that you have installed latest JDK

- To Create new Maven Project Click on file ->New->Others->Maven Project and Click on Next.

- Provide appropriate Details as required mentioned below:

- You may see Screen like below Now Right click on the project New->Package

- Right-click on the Package->Click New Class

- After clicking finish you may screen like this.

Dependency Injection of Selenium in Maven Project:
- In Pom.xml provide Selenium Dependency as shown in Snapshot below:


Java topics for Selenium we need to cover.
Frequently Asked Questions:
- Is it complex to move from Manual testing to Automation?
- What concepts of Java do I need to learn to use selenium webdriver?
- I am completely new to programming. Can I still learn Selenium?
- What is the best source to learn Java from Scratch?

A complete list of Java topics for Selenium
- Object Oriented Concept
- Class
- Object
- Inheritance
- Polymorphism
- Abstraction
- List of keywords, Interface in Java.
- Handle data types and usage of same.
- Control statements.
- Looping statements.
- String class
- Arrays
- Exception handling.
- Collection framework (List, Set)
- File handling.
- Packages and Eclipse usages.
Open Browser:
Command to invoke Browser:
WebDriver driver=new FirefoxDriver();Command invokes the Firefox browser, I hope the reader is familiar with creating the object in java if in case not then follow the link :

- WebDriver - webdriver is the interface which is inherited from SearchContext
- new - new is the keyword in java which creates an object (address space)in the heap area of CPU
- FirefoxDriver() - FirefoxDriver() is a constructor of FirefoxDriver class which implements all the methods in the present in the webdriver interface and this opens the Firefox Browser.
- driver - driver is reference variable , which refers the address space created on the heap.
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new FirefoxDriver(); } }
Open Web page:
get("url")a non-static method present in the FirefoxDriver class, it accepts a string as arguments and the string should be the website address.The best thing about the method is it will not give control to the next line till the page loads completely.
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); } }
Maximize Browser:
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); driver.manage().window().maximize(); } }
Browser Size
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); driver.manage().window().getSize(); } }
Get Url
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); String current_url= driver.getCurrentUrl(); System.out.println("Current Url is -->"+current_url); } }
Get Title
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); String title= driver.getTitle(); System.out.println("Current Title is -->"+title); } }
Get PageSource:
package Test_Package; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Test_Class { public static void main(String[] args) { WebDriver driver=new ChromeDriver(); driver.get("www.google.com"); String PageSource= driver.getPageSource(); System.out.println("Current PageSource is -->"+PageSource); } }
CHROME
Chrome Developer Tool:
Steps to open Developer Tool in Chrome :
- Press F12 key.
- Select More Tools > Developer Tools from Chrome's Main Menu.
- Right-click a page element and select Inspect.
- Press Command+Option+I (Mac) or Control+Shift+I (Windows, Linux).
- When we do one of the above-said things, Google opens developer tool like below.
- Navigate to elements tab, you can see the HTML source of the page
- If you want to inspect any page, you have to click the inspector and choose the element, now it opens the source code.


FIREFOX:
Firebug


Locators:
Locators provide a way to access the HTML elements from a web page. In Selenium, we can use locators to perform actions on the text boxes, links, checkboxes and other web elements.Locators are the basic building blocks of a web page. A web developer must use a proper and consistent locator scheme for a website. Also, a test engineer must choose the correct locator strategy to automate the online workflows.Selenium names eight types of locators to find the elements on a web page.- ID
- Name
- Link Text
- Partial Link Text
- Tag Name
- CSS Class
- CSS Selector
- XPath
Description:
ID:
id="user" class="required" type="text">
WebElement item = driver.findElement(By.id("user"));
Highlights:
It is preferable to have a unique id, so it is unlikely to meet similar values.Lowlights:
Feasible for elements with fixed IDs but not for the generated ones.Name:
id="user" name="admin" class="required" type="text">
WebElement locator = driver.findElement(By.name("admin"));
Highlights:
It is more appropriate to use it when you have a list of similar types of elements.Lowlights:
Using it with a dynamically generated list is tough.Link Text:
href="http://www.google.com">How to use locators?
WebElement item = driver.findElement(By.linkText("How to use locators?"));
Highlights:
- It’ll only work for anchor tags.
- Use it for checking navigation flows.
Lowlights:
You need to provide the link text for it to work.Partial Link Text:
href="http://www.google.com">How to use locators? WebElement item = driver.findElement(By.PartialLinkText("How to use locators?"));
Tag Name:
List<WebElement> linkElements = driver.findElements(By.tagName("results")); String[] linkTexts = new String[linkElements.size()]
CSS:
CSS class locator example: WebElement element =driver.findElement(By.className(“sample”));
- CSS Selector:
CSS Selector example: WebElement CheckElements = driver.findElements(By.cssSelector("input[id=email']"));
Highlights:
- Relatively speedier than using the XPath.
- Its usage is growing as the web pages are getting more style-centric.
- It’s easy to define a unique CSS locator as you can combine multiple CSS attributes.
Lowlights:
It’s not easy to form a CSS selector and requires a deeper understanding of the CSS/Javascript.XPATH:
Absolute XPath Example: HTML/head/body/table/tr/tdTo use locators like the XPath is easy as you give the direct element path. But the XPath would break when the element structure changes.II- Relative XPath.The relative XPath are easy to manage as they are short and concise. It is also better than the previous XPath style as it may survive the changes in the Page HTML to a certain degree. Though, building a relative XPath is time-consuming and quite difficult as you need to check all the nodes to form the path.
Relative XPath Example: //table/tr/td
Highlights:
Guarantees to find accurate locators.Lowlights:
- It is slow as compared to CSS.
- It’s browser dependent, and there are differences in IE vs. Firefox XPath implementations.
ChroPath
ChroPath is a developer tool which comes very handy in getting Xpaths and CSS selectors for web elements of a web page.- Chropath provides the following benefits:
- Locator Discovery
- Save Time
- Easy Maintenance
- Locator Discovery- Gives the best, robust locators just in a single click.
- Save Time- No more hit and trial locators. Get all your relevant XPath and CSS selectors which can be used directly in automation script mode.
- Easy Maintenance- Verify, edit and modify locators in no time and get the number of matching nodes and scroll matching elements into the view area.
Installation of Chropath
Chropath can be Installed from the following link for the Different Browsers: Chrome:
How to Use Chropath
- Click on the Plugin by Pressing F12.

- Inspect Element as shown in Figure below

Click the Element which is to be located

- Find the Relative and Absolute Xpath and CSS Selector Below, Look it is very simple.
