Selenium with Java
Learn Automation Testing with Selenium WebDriver
By Pallavi Yadav.
Why Selenium?
Selenium Architecture
Locators in Selenium
Basic Selenium WebDriver
Methods
agenda
Waits in Selenium
Select Class (Dropdown
Handling)
Action Class (Mouse &
Keyboard Actions)
Handling Frames
Capturing Screenshots
Data-Driven Framework using
Excel
Keyword-Driven Framework
using Excel
Conclusion
Why Selenium?
• Open-source automation tool
• Supports multiple browsers (Chrome, Firefox, Edge,
etc.)
• Works with multiple programming languages (Java,
Python, C#, etc.)
• Supports parallel execution with Grid
• Integrates with frameworks like TestNG, Cucumber,
and JUnit
Selenium Architecture
COMPONENTS:
SELENIUM WEBDRIVER - INTERACTS WITH
WEB ELEMENTS
JSON WIRE PROTOCOL - COMMUNICATION
LAYER
BROWSER DRIVERS - SPECIFIC TO BROWSERS
BROWSERS - CHROME, FIREFOX, EDGE, ETC.
Locators in Selenium
Types of Locators:
1. ID - driver.findElement(By.id("elementId"))
2. Name - driver.findElement(By.name("elementName"))
3. Class Name - driver.findElement(By.className("className"))
4. Tag Name - driver.findElement(By.tagName("tagName"))
5. Link Text - driver.findElement(By.linkText("LinkText"))
6. Partial Link Text - driver.findElement(By.partialLinkText("PartialText"))
7. CSS Selector - driver.findElement(By.cssSelector("CSSSelector"))
8. XPath - driver.findElement(By.xpath("XPathExpression"))
Basic Selenium WebDriver Methods
get() - Opens a URL
getTitle() - Retrieves page title
getCurrentUrl() - Retrieves current URL
findElement() - Locates a web element
findElements() - Locates multiple web elements
click() - Clicks a web element
sendKeys() - Enters text into a field
clear() - Clears text field
close() - Closes current browser window
quit() - Closes all browser windows
Locators in Selenium
Types of Locators:
1. ID - driver.findElement(By.id("elementId"))
2. Name - driver.findElement(By.name("elementName"))
3. Class Name - driver.findElement(By.className("className"))
4. Tag Name - driver.findElement(By.tagName("tagName"))
5. Link Text - driver.findElement(By.linkText("LinkText"))
6. Partial Link Text - driver.findElement(By.partialLinkText("PartialText"))
7. CSS Selector - driver.findElement(By.cssSelector("CSSSelector"))
8. XPath - driver.findElement(By.xpath("XPathExpression"))
Waits in Selenium
Types of Waits:
Select Class (Dropdown
Handling)
Used for handling dropdowns in Selenium
Action Class (Mouse & Keyboard
Actions)
Used for handling mouse and keyboard events
Handling Frames
Switching between frames
Capturing Screenshots
Take a screenshot using Selenium
Data-Driven Framework using Excel
Reading data from Excel using Apache POI
Keyword-Driven Framework using
Excel
o Storing actions in Excel and executing dynamically
o Keywords like click, sendKeys, navigateTo, etc.
Adding a Java Maven Project in Eclipse for
Selenium & TestNG
Steps to Create a Maven Project:
1. Open Eclipse IDE
2. Go to File > New > Project
3. Select Maven Project and click Next
4. Choose Create a simple project and click Next
5. Provide Group ID (e.g., com.selenium) and Artifact ID
(e.g., SeleniumProject)
6. Click Finish
7. Open pom.xml and add dependencies for Selenium
WebDriver and TestNG
8. Save pom.xml and update Maven project
9. Create a new TestNG class and start writing test
cases
Conclusion
SELENIUM IS A POWERFUL TOOL FOR WEB
AUTOMATION.
SUPPORTS MULTIPLE FRAMEWORKS.
CAN BE INTEGRATED WITH CI/CD TOOLS.
ENHANCES TEST AUTOMATION EFFICIENCY.
thank you