SlideShare a Scribd company logo
WebDriver Training
Trainer: Dipesh Bhatewara
www.digitalinfobytes.com
History
2
2004 2007 2009 2011
Selenium 1 WebDriver
Selenium2
WebDriver
 Is a Self Contained Library of APIs
 Uses browser capabilities over injected JavaScripts
 “Best fit” technology
 Clean & Object Oriented API
 Easy to maintain
 Faster than Selenium 1
 Tightly bound to the browser, no need of Selenium Server
 Bindings : Java, C#, Python, Ruby
 Android and iPhone support
3
Selenium Server in Selenium2
 Replicate Selenium RC functionalities
 Remote WebDriver
 Selenium Grid 2
4
WebDriver
WebDriver Interface
Firefox
Driver
Internet
Explorer
Driver
Chrome
Driver
HTML
Unit
Driver
Opera
Driver
Andriod
Driver
iPhone
Driver
5
API – Must Know
 Webdriver – Control Browser
 Webdriver driver = new FirefoxDriver();
 WebElement – works with elements on page
 WebElement username =
driver.findElement(By.id(“user”));
API – Must Know
 void get(“url”) - open the web page
 void quit() - close the browser
 List<WebElement> findElements(By by) - find elements (more than one
element)
API – Find Elements
 There are many different ways to find elements
 By.id(“objectId”)
 By.linkText(“textUsedInTheLink”)
 By.partialLinkText(“partOftextUsedInTheLink”)
 By.tagName(“HTMLNodeTag”)
 By.className(“cssClassOnObject”)
 By.cssSelector(“cssSelectorOfElement”)
 By.xpath(“//xpath/To/Element”)
 By.name(“elementName”)
API - Operations
 void click() - click on an element
 void submit() - perform a submit
 String getValue() – returns value set in the element
 void sendKeys(“keysToSend”) - input values
 void clear() - clear the input field
 String getElementName() – returns value of Name of the element
 String getAttriubute() – returns value of specified attribute of the element
 void Actions() - perform mouse, drag and drops and keyboard operations
www.time2test.co.uk !
API - windows and frames working with
Browser
 Windows
 driver.getWindowHandles()
 driver.switchTo().window.(“window_name”)
 Working with frames • driver.switchTo().frame.(“frame_name”)
Finding Dynamic Elements
 Does the ID of your element dynamically change?
<p id="bootcamp_dynamic_1234">This p tag has a dynamic id</p>
 Xpath notation to find the p tag on the page
"//p[contains(@id,'bootcamp_dynamic_')]"
Locator Strategies
 ID
 webDriver.findElement(By.id("logo"));
 Name
 webDriver.findElement(By.name("q"));
 Tag Name
 webDriver.findElement(By.tagName("H1"));
 Class name
 webDriver.findElements(By.className("sponsor_logos"));
 XPath
 webDriver.findElement(By.xpath("//section[@id=‘miniconfs’]/a[2]"));
 Link Text
 webDriver.findElements(By.linkText("About"));
 Partial Link Text
 webDriver.findElement(By.partialLinkText("visitcanberra"));
12
Sample Codes
 Clicking Button/Link/CheckBox
 Type in Textbox
driver.findElement(By.id("submitButton")).
click();
driver.findElement(By.name("fname")).sendKeys
("My First Name");
Sample Codes
 Selecting from Drop Down/Radio button
<select id="44"> <option value="1">xyz</option>
<option value="2">abc</option>
<option value="3">pqr</option>
</select>
WebElement e = driver.findElement(By.id("44"));
Select selectElement=new Select(e);
// both of the below statements will select first
option in the weblist
selectElement.selectByVisibleText("xyz");
selectElement.selectByValue("1");
Sample Codes
 Store text of targeted element
 Get page title
String dropdown =
driver.findElement(By.tagName("select")).getText();
driver.getTitle();
Sample Code for Demonstration
16
Let’s code
 Try the commands seen on your application under test using Selenium, Java,
TestNG and Eclipse
 Eclipse-Java-Selenium environment setup Reference -
http://qastuff.blogspot.in/2012/03/setting-up-selenium-web-driver-
eclipse.html
17
Page Interactions
 webElement.click()
 webElement.sendKeys(...)
 webElement.submit()
 Actions class -> Mouse Events / Drag and Drop
18
Advanced: Waits in Webdriver
 Waiting is having the automated task execution elapse a certain amount of
time before continuing with the next step.
 Worst way of waiting is Thread.sleep();
Advanced Example: Implicit Wait
 An implicit wait is to tell WebDriver to poll the DOM for a certain amount of
time when trying to find an element or elements if they are not immediately
available. The default setting is 0. Once set, the implicit wait is set for the
life of the WebDriver object instance.
WebDriver webdriver = new FirefoxDriver();
webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webdriver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement =
webdriver.findElement(By.id("myDynamicElement"));
Advanced Example: Explicit Wait
An explicit waits is code you define to wait for a certain condition to occur
before proceeding further in the code.
WebElement myDynamicElement = (new WebDriverWait(driver,
10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicE
lement")));
WebElement element =
wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
Some conditions for Explicit wait
 ExpectedConditions.elementToBeClickable(locator);
 ExpectedConditions.invisibilityOfElementLocated(locator);
 ExpectedConditions.alertIsPresent();
 ExpectedConditions.presenceOfElementLocated(locator);
 ExpectedConditions.textToBePresentInElement(locator, text);
 ExpectedConditions.visibilityOf(element);
Advanced Examples
 Capture Screenshot
File screenshot =
((TakesScreenshot)driver).getScreenshotAs(OutputType.
FILE);
FileUtils.copyFile(screenshot, new
File("D:screenshot.jpg"));
Best Practice
 To use implicit wait and explicit wait together
 Define implicit wait for driver after initialization
 This will define default implicit wait time frame for all findElements
 At the special places requiring more time, use explicit wait
Additional useful commands
 Polling the DOM for N seconds
 webDriver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
 Testing CSS properties
 webElement.getCssValue(“height”);
 Javascript execution
 JavascriptExecutor js = (JavascriptExecutor) webDriver;
 Long value = (Long) js.executeScript("return
window.scrollY");
 Navigation
 webDriver.navigate().back();
 webDriver.navigate().forward();
 webDriver.navigate().to(“url”); 25
Assignment
 Fill the form of registration on a test website of your choice.
 Run it on different browsers.
 Try to use waits.
26
Pop-up/Alert handling
 Pop up window
 driver.switchTo().window(windowHandle);
 Alerts
 alert = driver.switchTo().alert();
 alert.Accept();
 alert.Dismiss();
 Sample code Reference - http://qastuff.blogspot.in/2012/05/switch-to-
window-smart-way.html
27
Backward Compatibility with Selenium 1
Selenium selenium = new
WebDriverBackedSelenium(webDriver,
“http://osdc.com.au”);
selenium.open("http://osdc.com.au");
selenium.click("id=follow_twitter");
selenium.waitForPageToLoad("10000");
WebDriver webDriver = ((WebDriverBackedSelenium)
selenium).getUnderlyingWebDriver(); 28
Dipesh Bhatewara
Test Automation and Agile enthusiast.
LinkedIn -https://in.linkedin.com/pub/dipesh-bhatewara/2/498/612/en
Blog - http://qastuff.blogspot.in/, www.digitalinfobytes.com
Email - dipesh.bhatewara@outlook.com

More Related Content

PDF
Selenium webdriver
PDF
Introduction to Selenium and Ruby
DOC
Selenium Automation Using Ruby
PPT
Automated Testing With Watir
PPT
Introduction To Ruby Watir (Web Application Testing In Ruby)
PPTX
Selenium drivers
PPTX
Selenium training
PDF
Selenide
Selenium webdriver
Introduction to Selenium and Ruby
Selenium Automation Using Ruby
Automated Testing With Watir
Introduction To Ruby Watir (Web Application Testing In Ruby)
Selenium drivers
Selenium training
Selenide

What's hot (20)

PPT
Selenium testing - Handle Elements in WebDriver
KEY
Getting started with Selenium 2
PDF
PPTX
Dfc 2018 NativeScript
PPT
PDF
Selenium Introduction by Sandeep Sharda
PPTX
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
PDF
What is the taste of the Selenide
PDF
jQuery Proven Performance Tips & Tricks
PPT
What you can do In WatiR
PPTX
Protractor framework – how to make stable e2e tests for Angular applications
PDF
Javascript Test Automation Workshop (21.08.2014)
PDF
watir-webdriver
PDF
Tellurium At Rich Web Experience2009
PPTX
Introduction to Selenium Web Driver
PDF
Scraping recalcitrant web sites with Python & Selenium
PPTX
Selenium. going beyond the possible
PPTX
Development of automated tests for ext js based web sites
PDF
Tellurium.A.New.Approach.For.Web.Testing
PPTX
An Introduction to AngularJS End to End Testing using Protractor
Selenium testing - Handle Elements in WebDriver
Getting started with Selenium 2
Dfc 2018 NativeScript
Selenium Introduction by Sandeep Sharda
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
What is the taste of the Selenide
jQuery Proven Performance Tips & Tricks
What you can do In WatiR
Protractor framework – how to make stable e2e tests for Angular applications
Javascript Test Automation Workshop (21.08.2014)
watir-webdriver
Tellurium At Rich Web Experience2009
Introduction to Selenium Web Driver
Scraping recalcitrant web sites with Python & Selenium
Selenium. going beyond the possible
Development of automated tests for ext js based web sites
Tellurium.A.New.Approach.For.Web.Testing
An Introduction to AngularJS End to End Testing using Protractor
Ad

Similar to Web driver training (20)

PDF
Web driver selenium simplified
PPT
Java. Explicit and Implicit Wait. Testing Ajax Applications
PPTX
Selenium web driver
PPTX
Selenium.pptx
PPTX
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
PDF
Selenium course training institute ameerpet hyderabad
PDF
Selenium course training institute ameerpet hyderabad – Best software trainin...
PPTX
Web testing with Selenium
DOCX
Experienced Selenium Interview questions
PPTX
Selenium WebDriver
PDF
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
PDF
Selenium bootcamp slides
PPTX
Introduction to selenium web driver
PDF
Selenium Full Material( apprendre Selenium).pdf
PPTX
2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!
PPTX
Selenium web driver
PPTX
Presentation(Q3).pptxgdfgfgwdfwgdfwgdfwgdfwwwgsvwgdvgdvgdvwg
PDF
Selenium webdriver practical_guide
PPTX
UI Automation Quirks
PPSX
Selenium WebDriver with Java
Web driver selenium simplified
Java. Explicit and Implicit Wait. Testing Ajax Applications
Selenium web driver
Selenium.pptx
Top 15 Selenium WebDriver Interview Questions and Answers.pptx
Selenium course training institute ameerpet hyderabad
Selenium course training institute ameerpet hyderabad – Best software trainin...
Web testing with Selenium
Experienced Selenium Interview questions
Selenium WebDriver
Top 15 Selenium WebDriver Interview Questions and Answers.pdf
Selenium bootcamp slides
Introduction to selenium web driver
Selenium Full Material( apprendre Selenium).pdf
2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!
Selenium web driver
Presentation(Q3).pptxgdfgfgwdfwgdfwgdfwgdfwwwgsvwgdvgdvgdvwg
Selenium webdriver practical_guide
UI Automation Quirks
Selenium WebDriver with Java
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
August Patch Tuesday
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A comparative study of natural language inference in Swahili using monolingua...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
cloud_computing_Infrastucture_as_cloud_p
NewMind AI Weekly Chronicles - August'25-Week II
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Empathic Computing: Creating Shared Understanding
Group 1 Presentation -Planning and Decision Making .pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
Assigned Numbers - 2025 - Bluetooth® Document
August Patch Tuesday
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A comparative analysis of optical character recognition models for extracting...

Web driver training

  • 1. WebDriver Training Trainer: Dipesh Bhatewara www.digitalinfobytes.com
  • 2. History 2 2004 2007 2009 2011 Selenium 1 WebDriver Selenium2
  • 3. WebDriver  Is a Self Contained Library of APIs  Uses browser capabilities over injected JavaScripts  “Best fit” technology  Clean & Object Oriented API  Easy to maintain  Faster than Selenium 1  Tightly bound to the browser, no need of Selenium Server  Bindings : Java, C#, Python, Ruby  Android and iPhone support 3
  • 4. Selenium Server in Selenium2  Replicate Selenium RC functionalities  Remote WebDriver  Selenium Grid 2 4
  • 6. API – Must Know  Webdriver – Control Browser  Webdriver driver = new FirefoxDriver();  WebElement – works with elements on page  WebElement username = driver.findElement(By.id(“user”));
  • 7. API – Must Know  void get(“url”) - open the web page  void quit() - close the browser  List<WebElement> findElements(By by) - find elements (more than one element)
  • 8. API – Find Elements  There are many different ways to find elements  By.id(“objectId”)  By.linkText(“textUsedInTheLink”)  By.partialLinkText(“partOftextUsedInTheLink”)  By.tagName(“HTMLNodeTag”)  By.className(“cssClassOnObject”)  By.cssSelector(“cssSelectorOfElement”)  By.xpath(“//xpath/To/Element”)  By.name(“elementName”)
  • 9. API - Operations  void click() - click on an element  void submit() - perform a submit  String getValue() – returns value set in the element  void sendKeys(“keysToSend”) - input values  void clear() - clear the input field  String getElementName() – returns value of Name of the element  String getAttriubute() – returns value of specified attribute of the element  void Actions() - perform mouse, drag and drops and keyboard operations www.time2test.co.uk !
  • 10. API - windows and frames working with Browser  Windows  driver.getWindowHandles()  driver.switchTo().window.(“window_name”)  Working with frames • driver.switchTo().frame.(“frame_name”)
  • 11. Finding Dynamic Elements  Does the ID of your element dynamically change? <p id="bootcamp_dynamic_1234">This p tag has a dynamic id</p>  Xpath notation to find the p tag on the page "//p[contains(@id,'bootcamp_dynamic_')]"
  • 12. Locator Strategies  ID  webDriver.findElement(By.id("logo"));  Name  webDriver.findElement(By.name("q"));  Tag Name  webDriver.findElement(By.tagName("H1"));  Class name  webDriver.findElements(By.className("sponsor_logos"));  XPath  webDriver.findElement(By.xpath("//section[@id=‘miniconfs’]/a[2]"));  Link Text  webDriver.findElements(By.linkText("About"));  Partial Link Text  webDriver.findElement(By.partialLinkText("visitcanberra")); 12
  • 13. Sample Codes  Clicking Button/Link/CheckBox  Type in Textbox driver.findElement(By.id("submitButton")). click(); driver.findElement(By.name("fname")).sendKeys ("My First Name");
  • 14. Sample Codes  Selecting from Drop Down/Radio button <select id="44"> <option value="1">xyz</option> <option value="2">abc</option> <option value="3">pqr</option> </select> WebElement e = driver.findElement(By.id("44")); Select selectElement=new Select(e); // both of the below statements will select first option in the weblist selectElement.selectByVisibleText("xyz"); selectElement.selectByValue("1");
  • 15. Sample Codes  Store text of targeted element  Get page title String dropdown = driver.findElement(By.tagName("select")).getText(); driver.getTitle();
  • 16. Sample Code for Demonstration 16
  • 17. Let’s code  Try the commands seen on your application under test using Selenium, Java, TestNG and Eclipse  Eclipse-Java-Selenium environment setup Reference - http://qastuff.blogspot.in/2012/03/setting-up-selenium-web-driver- eclipse.html 17
  • 18. Page Interactions  webElement.click()  webElement.sendKeys(...)  webElement.submit()  Actions class -> Mouse Events / Drag and Drop 18
  • 19. Advanced: Waits in Webdriver  Waiting is having the automated task execution elapse a certain amount of time before continuing with the next step.  Worst way of waiting is Thread.sleep();
  • 20. Advanced Example: Implicit Wait  An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. WebDriver webdriver = new FirefoxDriver(); webdriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); webdriver.get("http://somedomain/url_that_delays_loading"); WebElement myDynamicElement = webdriver.findElement(By.id("myDynamicElement"));
  • 21. Advanced Example: Explicit Wait An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicE lement"))); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
  • 22. Some conditions for Explicit wait  ExpectedConditions.elementToBeClickable(locator);  ExpectedConditions.invisibilityOfElementLocated(locator);  ExpectedConditions.alertIsPresent();  ExpectedConditions.presenceOfElementLocated(locator);  ExpectedConditions.textToBePresentInElement(locator, text);  ExpectedConditions.visibilityOf(element);
  • 23. Advanced Examples  Capture Screenshot File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType. FILE); FileUtils.copyFile(screenshot, new File("D:screenshot.jpg"));
  • 24. Best Practice  To use implicit wait and explicit wait together  Define implicit wait for driver after initialization  This will define default implicit wait time frame for all findElements  At the special places requiring more time, use explicit wait
  • 25. Additional useful commands  Polling the DOM for N seconds  webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  Testing CSS properties  webElement.getCssValue(“height”);  Javascript execution  JavascriptExecutor js = (JavascriptExecutor) webDriver;  Long value = (Long) js.executeScript("return window.scrollY");  Navigation  webDriver.navigate().back();  webDriver.navigate().forward();  webDriver.navigate().to(“url”); 25
  • 26. Assignment  Fill the form of registration on a test website of your choice.  Run it on different browsers.  Try to use waits. 26
  • 27. Pop-up/Alert handling  Pop up window  driver.switchTo().window(windowHandle);  Alerts  alert = driver.switchTo().alert();  alert.Accept();  alert.Dismiss();  Sample code Reference - http://qastuff.blogspot.in/2012/05/switch-to- window-smart-way.html 27
  • 28. Backward Compatibility with Selenium 1 Selenium selenium = new WebDriverBackedSelenium(webDriver, “http://osdc.com.au”); selenium.open("http://osdc.com.au"); selenium.click("id=follow_twitter"); selenium.waitForPageToLoad("10000"); WebDriver webDriver = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver(); 28
  • 29. Dipesh Bhatewara Test Automation and Agile enthusiast. LinkedIn -https://in.linkedin.com/pub/dipesh-bhatewara/2/498/612/en Blog - http://qastuff.blogspot.in/, www.digitalinfobytes.com Email - dipesh.bhatewara@outlook.com