KEMBAR78
Selenium Basics and Overview topics.pptx
Selenium Basics and
Overview
Chapter 1
Topics
 Introduction to Browser Automation
 What is Selenium and Overview
 History and evolution of Selenium
 Selenium Components (WebDriver vs Selenium IDE vs Selenium Grid)
 Supported programming languages
 Cross-browser and cross-platform compatibility.
 1. Reason for Cross Browser Testing
 2. Cross-platform testing (such as Windows, iOS, Android, macOS, and Linux)
 Advantages and limitations of Selenium
Introduction to Browser Automation
Perform Testing in any web browsers using Automation
tools such as Selenium, Cypress, Playwright etc. to
reduce the manual effort and deliver with more quality in
minimum hours.
What is Selenium and Overview
Selenium WebDriver is a powerful and widely used open-source tool
for automating web browsers. It provides a programming interface
to interact with web browsers, allowing users to automate browser
actions, navigate web pages, and perform functional testing.
History and evolution of Selenium
• Selenium was established in 2004 at Thoughtworks in Chicago, by Jason
Huggins. It spans over two decades, transforming from a simple tool into
most demanded Automation tool in the market.
• Initially, Selenium started with Selenium RC, which allowed for
automated testing of web applications. It then evolved into Selenium
WebDriver, enhancing its capabilities and adapting to the needs of modern
web applications.
Selenium Components (WebDriver vs Selenium IDE vs Selenium Grid)
Selenium IDE Selinium RC Selinium Web-driver
Only works on Mozilla Firefox Internet Explorer, Mozilla
Firefox, Google Chrome, Safari
and Opera
Works on latest versions of major
browsers- Firefox, IE, Edge,
Chrome
Record and Play tool No Record and Play No Record and Play
JavaScript-based core engine JavaScript-based core engine Interacts natively with browser
application
No programming knowledge
required
Programming knowledge
required
Programming knowledge
required
Supported programming languages
Selenium WebDriver supports multiple programming
languages such as Python, Java, C#, Ruby, JavaScript,
making it versatile for developers working in different
technology stacks
Cross-browser and cross-platform compatibility
Reason for Cross Browser
Testing:
 Font size mismatch in
different browsers.
 Page alignment and div
size
 Browser incompatibility
with OS. Etc
Cross-platform testing (such as Windows, iOS,
Android, macOS, and Linux):
 To ensure that your application functions flawlessly
on different platforms, it must be rigorously tested
across these various environments.
 Cross-platform testing is crucial for identifying and
resolving issues related to usability, consistency,
user interface, and performance across different
devices, browser versions, and operating systems.
Advantages and limitations of Selenium
Advantages:
 Selenium is an open source, freeware and portable tool.
 Selenium supports variety of languages that include Java, Perl, Python, C#, Ruby, Groovy, Java Script and etc.
 Selenium supports many operating systems like Windows, Linux, Unix etc.
 Selenium supports many browsers like Internet explorer, Chrome, Firefox, Edge, Safari etc.
 Selenium can be integrated with Maven kind of framework for source code compilation.
 Selenium can be integrated with TestNG testing framework for testing our applications and generating reports.
 Selenium can be integrated with Jenkins or Azure devops for continuous integration.
 Selenium can be integrated with other open source tools for supporting other features.
 Selenium can be used for Android, IPhone, Blackberry etc. based application testing.
Limitations Of Selenium
• Selenium doesn’t support windows based applications. It supports only web-based applications which
imply only website testing is possible with Selenium.
• Windows-based pops are part of the operating system. It’s beyond Selenium’s capabilities. You can
make use of AutoIT to handle the windows based popups.
• Handling captcha is a limitation in selenium. There are some third-party tools to automate captcha
(2Captcha, Anti-Captcha, and DeathByCaptcha), however, you cannot achieve 100% results.
• It is not possible to perform testing on images. To do so, you need to integrate Selenium with Sikuli
for image-based testing.
• Maintenance is required frequently to maintain the Automation script.
• Coding knowledge is must in order to develop the script.
Selenium Architecture
Chapter 2
Topics
•What is Selenium Webdriver
•WebDriver Architecture
What is Selenium Webdriver
• WebDriver is one of the component in selenium.
• WebDriver is a java interface.
• WebDriver is an API( Application Programming interface)
WebDriver Architecture
 Selenium supports various programming languages such as Java, Python, C#,
Ruby, and more. These libraries provide bindings or APIs that allow you to
interact with Selenium and control the browser using the chosen
programming language. For example, if you are using Java, you would use the
Selenium Java client library, and if you are using Python, you would use the
Selenium Python client library
 JSON Wire Protocol is a RESTful web service that acts as a communication
bridge between the Selenium Client Libraries and the Browser Drivers. It
defines a standard way for sending commands to the browser and receiving
responses.
 Browser Drivers are executable files or libraries specific to each browser.
They act as intermediaries between the Selenium Client Libraries and the
actual browsers. The client libraries communicate with the browser drivers,
and the drivers, in turn, control the respective browsers.
Setting up Selenium Environment
Chapter - 3
Installation
• Installing Java Development Kit (JDK)
Click here for JDK installation
• Installing Eclipse (IDE)
Click here for Eclipse installation
• Selenium WebDriver installation
Click here for Selenium WebDriver installation
Selenium Environment
Chapter - 4
Topics
• How to identify the locators in web page
• Launching Browsers in Selenium
How to identify the locators in web page
Step 1: Right click on the click where you need to interact with
Step 2 : Click Inspect à DOM structure will be getting opened
Step 3: hover on the highlighted tag à Ensure that it is locating expected
element in UI
Launching Browsers in Selenium
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.addArguments("--start-maximized");
edgeOptions.addArguments("--remote-allow-origins=*");
WebDriver driver = new EdgeDriver(edgeOptions);
driver.get("https://www.google.com");
driver.close();
Locating Various Web elements
Chapter - 5
Topics
•Types of Locators in Selenium
•Dropdown handling
Types of Locators in Selenium
• ID
• Name
• Class
• Link text
• Partial link text
• CSS Selector
• Xpath
Click here to find locator details.
Dropdown handling
Using Select class –
Syntax
Syntax:
Select objSelect = new Select(driver.findElement(By.id("search-box")));
objSelect.selectByVisibleText("Economy");
objSelect.selectByValue("Value");
objSelect.selectByIndex(1);
How to get all the options in dropdown :
List<WebElement> options = objSelect.getOptions();
Example
Example:
driver.findElement(By.xpath("//a[@id='flights']")).click();
Select objSelect = new
Select(driver.findElement(By.xpath("//select[@name='sr_cabin_class']")));
objSelect.selectByVisibleText("Business");
List<WebElement> options = objSelect.getOptions();
for(WebElement dropdown: options) {
System.out.println(dropdown.getText());
}
Without using Select class –
driver.findElement(By.xpath("//a[@id='flights']")).click();
driver.findElement(By.xpath("//select[@name='sr_cabin_class']")).click();
List<WebElement> options = driver.findElements(By.xpath("//select[@name='sr_cabin_class']/option"));
for(int i=0; i<=options.size(); i++) {
String value = options.get(i).getText();
if(value.equals("Business")) {
options.get(i).click();
break;
}
Find Radio Element
Select as text:
//
div[contains(@class,'Text
-module__root--variant')
and text ()='One-way']
Select as button:
//
div[contains(@class,'Text
-module__root--variant')
and text
()='One-way']/preceding::
span[contains(@class,'Inp
utRadio-module')][1]
Chapter 6
Desired Capabilities in Selenium Webdriver
HashMap<String, Object> edgePrefs = new HashMap<String, Object>();
edgePrefs.put("profile.default_content_settings.popups", 0);
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.addArguments("--start-maximized");
edgeOptions.addArguments("--remote-allow-origins=*");
WebDriver driver = new EdgeDriver(edgeOptions);
Selenium webDriver commands and Web
elements interactions
Chapter - 7
Topics
• Selenium WebDriver- Commands
• Text fields and buttons
• Find Element VS FindElements in Selenium WebDriver - check order
• Selenium WebDriver- Commands:
• Text fields and buttons
driver.get("https://www.booking.com");
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
driver.findElement(By.xpath("//
input[@name='ss']")).sendKeys("Chennai");
driver.findElement(By.xpath("//li[contains(@id,'autocomplete-
result')]//div[text()='Chennai']")).click();
Find Element VS FindElements in
Selenium WebDriver- check order
Aspect FindElement FindElements
Purpose FindElement Locate a single web element FindElements Locate multiple web elements
Return
Type
FindElement returns a WebElement FindElements return List<WebElement>
Behavior if
Not
Found
FindElement throws
NoSuchElementException
FindElements returns an empty list
First Matching It returns the first matching element It returns all matching elements
Element
Syntax WebElement element =
driver.findElement(By.id("elementId"));
List<WebElement> elements =
driver.findElements(By.className("elementClass"));
Example
driver.findElement(By.xpath("//input[@name='ss']")).click();
List<WebElement> options = driver.findElements(By.xpath("//div[text()='Popular
destinations nearby']/following-sibling::ul/li//span/following-sibling::div/div[1]"));
for(int i=0; i<=options.size(); i++) {
String value = options.get(i).getText();
if(value.startsWith("V")) {
options.get(i).click();
break;
}
}

Selenium Basics and Overview topics.pptx

  • 1.
  • 2.
    Topics  Introduction toBrowser Automation  What is Selenium and Overview  History and evolution of Selenium  Selenium Components (WebDriver vs Selenium IDE vs Selenium Grid)  Supported programming languages  Cross-browser and cross-platform compatibility.  1. Reason for Cross Browser Testing  2. Cross-platform testing (such as Windows, iOS, Android, macOS, and Linux)  Advantages and limitations of Selenium
  • 3.
    Introduction to BrowserAutomation Perform Testing in any web browsers using Automation tools such as Selenium, Cypress, Playwright etc. to reduce the manual effort and deliver with more quality in minimum hours.
  • 4.
    What is Seleniumand Overview Selenium WebDriver is a powerful and widely used open-source tool for automating web browsers. It provides a programming interface to interact with web browsers, allowing users to automate browser actions, navigate web pages, and perform functional testing.
  • 5.
    History and evolutionof Selenium • Selenium was established in 2004 at Thoughtworks in Chicago, by Jason Huggins. It spans over two decades, transforming from a simple tool into most demanded Automation tool in the market. • Initially, Selenium started with Selenium RC, which allowed for automated testing of web applications. It then evolved into Selenium WebDriver, enhancing its capabilities and adapting to the needs of modern web applications.
  • 6.
    Selenium Components (WebDrivervs Selenium IDE vs Selenium Grid) Selenium IDE Selinium RC Selinium Web-driver Only works on Mozilla Firefox Internet Explorer, Mozilla Firefox, Google Chrome, Safari and Opera Works on latest versions of major browsers- Firefox, IE, Edge, Chrome Record and Play tool No Record and Play No Record and Play JavaScript-based core engine JavaScript-based core engine Interacts natively with browser application No programming knowledge required Programming knowledge required Programming knowledge required
  • 7.
    Supported programming languages SeleniumWebDriver supports multiple programming languages such as Python, Java, C#, Ruby, JavaScript, making it versatile for developers working in different technology stacks
  • 8.
    Cross-browser and cross-platformcompatibility Reason for Cross Browser Testing:  Font size mismatch in different browsers.  Page alignment and div size  Browser incompatibility with OS. Etc Cross-platform testing (such as Windows, iOS, Android, macOS, and Linux):  To ensure that your application functions flawlessly on different platforms, it must be rigorously tested across these various environments.  Cross-platform testing is crucial for identifying and resolving issues related to usability, consistency, user interface, and performance across different devices, browser versions, and operating systems.
  • 9.
    Advantages and limitationsof Selenium Advantages:  Selenium is an open source, freeware and portable tool.  Selenium supports variety of languages that include Java, Perl, Python, C#, Ruby, Groovy, Java Script and etc.  Selenium supports many operating systems like Windows, Linux, Unix etc.  Selenium supports many browsers like Internet explorer, Chrome, Firefox, Edge, Safari etc.  Selenium can be integrated with Maven kind of framework for source code compilation.  Selenium can be integrated with TestNG testing framework for testing our applications and generating reports.  Selenium can be integrated with Jenkins or Azure devops for continuous integration.  Selenium can be integrated with other open source tools for supporting other features.  Selenium can be used for Android, IPhone, Blackberry etc. based application testing.
  • 10.
    Limitations Of Selenium •Selenium doesn’t support windows based applications. It supports only web-based applications which imply only website testing is possible with Selenium. • Windows-based pops are part of the operating system. It’s beyond Selenium’s capabilities. You can make use of AutoIT to handle the windows based popups. • Handling captcha is a limitation in selenium. There are some third-party tools to automate captcha (2Captcha, Anti-Captcha, and DeathByCaptcha), however, you cannot achieve 100% results. • It is not possible to perform testing on images. To do so, you need to integrate Selenium with Sikuli for image-based testing. • Maintenance is required frequently to maintain the Automation script. • Coding knowledge is must in order to develop the script.
  • 11.
  • 12.
    Topics •What is SeleniumWebdriver •WebDriver Architecture
  • 13.
    What is SeleniumWebdriver • WebDriver is one of the component in selenium. • WebDriver is a java interface. • WebDriver is an API( Application Programming interface)
  • 14.
    WebDriver Architecture  Seleniumsupports various programming languages such as Java, Python, C#, Ruby, and more. These libraries provide bindings or APIs that allow you to interact with Selenium and control the browser using the chosen programming language. For example, if you are using Java, you would use the Selenium Java client library, and if you are using Python, you would use the Selenium Python client library  JSON Wire Protocol is a RESTful web service that acts as a communication bridge between the Selenium Client Libraries and the Browser Drivers. It defines a standard way for sending commands to the browser and receiving responses.  Browser Drivers are executable files or libraries specific to each browser. They act as intermediaries between the Selenium Client Libraries and the actual browsers. The client libraries communicate with the browser drivers, and the drivers, in turn, control the respective browsers.
  • 15.
    Setting up SeleniumEnvironment Chapter - 3
  • 16.
    Installation • Installing JavaDevelopment Kit (JDK) Click here for JDK installation • Installing Eclipse (IDE) Click here for Eclipse installation • Selenium WebDriver installation Click here for Selenium WebDriver installation
  • 17.
  • 18.
    Topics • How toidentify the locators in web page • Launching Browsers in Selenium
  • 19.
    How to identifythe locators in web page Step 1: Right click on the click where you need to interact with
  • 20.
    Step 2 :Click Inspect à DOM structure will be getting opened
  • 21.
    Step 3: hoveron the highlighted tag à Ensure that it is locating expected element in UI
  • 22.
    Launching Browsers inSelenium EdgeOptions edgeOptions = new EdgeOptions(); edgeOptions.addArguments("--start-maximized"); edgeOptions.addArguments("--remote-allow-origins=*"); WebDriver driver = new EdgeDriver(edgeOptions); driver.get("https://www.google.com"); driver.close();
  • 23.
    Locating Various Webelements Chapter - 5
  • 24.
    Topics •Types of Locatorsin Selenium •Dropdown handling
  • 25.
    Types of Locatorsin Selenium • ID • Name • Class • Link text • Partial link text • CSS Selector • Xpath Click here to find locator details.
  • 26.
  • 27.
    Syntax Syntax: Select objSelect =new Select(driver.findElement(By.id("search-box"))); objSelect.selectByVisibleText("Economy"); objSelect.selectByValue("Value"); objSelect.selectByIndex(1); How to get all the options in dropdown : List<WebElement> options = objSelect.getOptions();
  • 28.
    Example Example: driver.findElement(By.xpath("//a[@id='flights']")).click(); Select objSelect =new Select(driver.findElement(By.xpath("//select[@name='sr_cabin_class']"))); objSelect.selectByVisibleText("Business"); List<WebElement> options = objSelect.getOptions(); for(WebElement dropdown: options) { System.out.println(dropdown.getText()); }
  • 29.
    Without using Selectclass – driver.findElement(By.xpath("//a[@id='flights']")).click(); driver.findElement(By.xpath("//select[@name='sr_cabin_class']")).click(); List<WebElement> options = driver.findElements(By.xpath("//select[@name='sr_cabin_class']/option")); for(int i=0; i<=options.size(); i++) { String value = options.get(i).getText(); if(value.equals("Business")) { options.get(i).click(); break; }
  • 30.
    Find Radio Element Selectas text: // div[contains(@class,'Text -module__root--variant') and text ()='One-way'] Select as button: // div[contains(@class,'Text -module__root--variant') and text ()='One-way']/preceding:: span[contains(@class,'Inp utRadio-module')][1]
  • 31.
    Chapter 6 Desired Capabilitiesin Selenium Webdriver HashMap<String, Object> edgePrefs = new HashMap<String, Object>(); edgePrefs.put("profile.default_content_settings.popups", 0); EdgeOptions edgeOptions = new EdgeOptions(); edgeOptions.addArguments("--start-maximized"); edgeOptions.addArguments("--remote-allow-origins=*"); WebDriver driver = new EdgeDriver(edgeOptions);
  • 32.
    Selenium webDriver commandsand Web elements interactions Chapter - 7
  • 33.
    Topics • Selenium WebDriver-Commands • Text fields and buttons • Find Element VS FindElements in Selenium WebDriver - check order
  • 34.
  • 35.
    • Text fieldsand buttons driver.get("https://www.booking.com"); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.findElement(By.xpath("// input[@name='ss']")).sendKeys("Chennai"); driver.findElement(By.xpath("//li[contains(@id,'autocomplete- result')]//div[text()='Chennai']")).click();
  • 36.
    Find Element VSFindElements in Selenium WebDriver- check order Aspect FindElement FindElements Purpose FindElement Locate a single web element FindElements Locate multiple web elements Return Type FindElement returns a WebElement FindElements return List<WebElement> Behavior if Not Found FindElement throws NoSuchElementException FindElements returns an empty list First Matching It returns the first matching element It returns all matching elements Element Syntax WebElement element = driver.findElement(By.id("elementId")); List<WebElement> elements = driver.findElements(By.className("elementClass"));
  • 37.
  • 38.
    driver.findElement(By.xpath("//input[@name='ss']")).click(); List<WebElement> options =driver.findElements(By.xpath("//div[text()='Popular destinations nearby']/following-sibling::ul/li//span/following-sibling::div/div[1]")); for(int i=0; i<=options.size(); i++) { String value = options.get(i).getText(); if(value.startsWith("V")) { options.get(i).click(); break; } }