This Selenium WebDriver tutorial talks about the drawbacks of Selenium RC and what was the need for Selenium WebDriver. It goes into the details of the avantages that WebDriver has over RC and how it replaced RC for automation testing. This tutorial will also tell you how WebDriver works and what are the different browser drivers you can use for testing. Watch the video to get a demonstration on how to locate various elements/ objects on the browser and how operations can be performed on those browser elements/ objects by writing Java code in Eclipse IDE.
Watch the video here: https://www.youtube.com/watch?v=ph3NJm4Z7m4
2. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
What Will You Learn Today?
What does Selenium
WebDriver do?
Why use WebDriver?
Drawbacks of Selenium RC
How does WebDriver work?
What are Elements/ Objects? How to locate them? Hands-On: Testing Dynamic
Web Applications
1 2 3
4 65
4. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
RC & WebDriver Similarities
Both RC and WebDriver support the use of different programming languages to design test scripts
Programming Language
Both RC and WebDriver support running tests in different browsers
Web Browser
Development Environment
Neither RC and WebDriver support use of IDE; only support for programming interface
Web Element Locator
Both RC and WebDriver make use of Elements/ Object locators/ WebDriver methods
8. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Advantages Of WebDriver Over RC
SELENIUM WEBDRIVER
Simple Architecture
Slower because it uses a
Javascript program called
Selenium Core
RC Server is the middleman in the
interactions between browser & user
No support for
HTMLUnit browser
Faster because it interacts
with browser directly
Direct Interaction with user
Support for HTMLUnit
browser
SELENIUM RC
Complex Architecture
11. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
I can use
WebDriver for
testing on local
machine
But, what
about testing
on a remote
machine
NOTE: While testing on a remote machine, commands from WebDriver go to Selenium
RC Server which is then interpreted on remote machine to automate the browser
I can use both RC
server and
WebDriver while
testing on remote
machine
RC To The Rescue For WebDriver
13. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
What Is Selenium WebDriver?
Selenium WebDriver is a programming interface to create and execute test cases
Test cases are created and executed using Elements locators/ Object locators/
WebDriver methods
Selenium WebDriver has only a programming interface; not IDE
Fast as it interacts with browser directly; RC needs RC server to interact with browser
•Each browser has its own driver on which the application runs. Selenium WebDriver
makes direct calls to the browser
14. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
WebDriver Features & Drawbacks
• Supports most Programming languages, Browsers & Operating systems
• Overcomes limitations of Selenium 1 like file upload, download, pop-ups & dialogs barrier
• WebDriver's API is simpler than RC's API. It does not contain redundant & confusing commands
• Supports Batch testing, Cross browser testing & Data driven testing
Selenium WebDriver Limitations
Selenium WebDriver Features
• Detailed test reports cannot be generated; RC generates detailed reports
• It doesn’t have IDE; difficult to create test cases
19. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Browser Elements & Its Operations
Launch browser, Navigate to specified Url,
Refresh, Close browser
Browser
Return page title, return page Url
Page
Click the link, check the existence, check enabled status
Link
Click the button, check displayed status, enabled
status, return button name
Button
Return image title, download/ upload image,
click image link
Image
Launch browser, Navigate to specified Url,
Refresh, Close browser
Text Area/ Error Message
Check display status/ enable status/ select/ unselect
Radio button/ Check box
Check display status/ enable status/ select item
Drop down box/ List box/ Combo box
Switch from Top window to specified frame,
Frame to top window
Frame
Return specified cell value, Return row
count, column count
Web Table/ HTML Table
21. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Methods/ Functions On Web Elements
This function is used to open a specified URL in the
browser window
Syntax:- driver.get(“URL”);
Example:- driver.get(“https://www.google.com”);
Get
This function is used to get the title of the
current page in the browser
Syntax:-
driver.getTitle();
Get Title
This function is used to get the URL of the current
page in the browser
Syntax:-
driver.getCurrentUrl();
Get Current URL
This function is used to get the source code of the
current page
Syntax:-
driver.getPageSource();
Get Page Source
Get Commands N a v i gate C o m man ds O t h e r B rows er C o m mands O t h e r C o m mands
22. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Methods/ Functions On Web Elements
This function is used to navigate to a new page in the
current browser window
Syntax:- driver.navigate().to(“URL”);
Example:- driver.navigate(). to(“https://www.google.com”);
Navigate To
This function is used to refresh the current page
in the browser window
Syntax:-
driver.navigate().refresh();
Navigate Refresh
This function is used to navigate to the web page
visited after the current page in the browser history
Syntax:-
driver.navigate().forward();
Navigate Forward
This function is used to navigate to the previously
visited page in the current window
Syntax:-
driver.navigate().back();
Navigate Back
G e t C o m mands Navigate Commands O t h e r B rows er C o m mands O t h e r C o m mands
23. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Methods/ Functions On Web Elements
This command is used to close the current page in the browser window
Syntax:- driver.close();
Close
This function is used to quit the browser window
Syntax:- driver.quit();
Quit
G e t C o m mands N a v i gate C o m man ds Other Browser Commands O t h e r C o m mands
24. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Methods/ Functions On Web Elements
findElement Command
This command is used to find elements/ objects on a web page
Example:- driver.findElement(By.name(“google”));
click Command
This command is used to click on an element/ object on the web page
Example:- driver.findElement(By.linkText(“Youtube”)).click();
sendKeys Command
This command is used to send characters/ text to the text box in the web page
Example:- driver.findElement(By.id(“Content-1”)).sendKeys(“18776”);
G e t C o m mands N a v i gate C o m man ds Other CommandsO t h e r B rows er C o m mands
26. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Web Elements And Locators
We can identify various elements on the web using Locators.
Locators are addresses that identify a web element uniquely within the page.
There are 8 Locators in Selenium to identify Elements:
• By ID
• By Name
• By Class Name
• By Tag Name
• By Link Text
• By Partial Link Text
• By CSS
• By XPATH
27. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
Elements on the web page can be located using Element ID
Every element on a web page has a unique ID
The ID can also be auto generated
Syntax:-
driver.findElement(By.id(“xxx”));
Example:
driver.findElement(By.id(“Content-1”)).sendKeys(“18776”);
By ID B y N a m e B y C l a s s N ame B y Ta g N a m e B y L i n k Tex t B y P a rti al L i n k Text B y CS SB y X PATH
28. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
Elements on the web page can also be located using Element Name
Every element on a web page has a unique Name
Syntax:-
driver.findElement(By.name(“xxx”));
Example:
driver.findElement(By.name(“Email”)).sendKeys(abc@edureka.co);
B y I D By Name B y C l a s s N ame B y Ta g N a m e B y L i n k Tex t B y P a rti al L i n k Text B y CS SB y X PATH
29. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
Elements on the web page can also be located using Element’s Class Name
Class Name can be the same for more than one Element
Syntax:-
driver.findElement(By.className(“xxx”));
Example:
driver.findElement(By.className(“Country”).sendKeys(“India”);
B y N a m e By Class Name B y Ta g N a m e B y L i n k Tex t B y P a rti al L i n k Text B y CS SB y X PATHB y I D
30. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
B y N a m e B y C l a s s N ame By Tag Name B y L i n k Tex tB y I D
Elements on the web page can also be located using Element’s Tag Name
Syntax:-
driver.findElement(By.tagName(“xxx”));
Example:
driver.findElement(By.tagName(“A1”)).sendKeys(“India-123”);
B y P a rti al L i n k Text B y CS SB y X PATH
31. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
B y N a m e B y C l a s s N ame B y Ta g N a m e By Link TextB y I D
Any hyperlinked word on the web page can be located by using the exact
word as it is
Syntax:-
driver.findElement(By.linkText(“xxx”));
Example:
driver.findElement(By.linkText(“Youtube”)).click();
B y P a rti al L i n k Text B y CS SB y X PATH
32. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
B y N a m e B y C l a s s N ame B y Ta g N a m e B y L i n k Tex tB y I D
Any hyperlinked word on the web page can also be located by using the
word partially
Syntax:-
driver.findElement(By.partialLinkText(“xxx”));
Example:
driver.findElement(By.partialLinkText(“Youtu”)).click();
By Partial Link Text B y CS SB y X PATH
33. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
B y N a m e B y C l a s s N ame B y Ta g N a m e B y L i n k Tex tB y I D
This attribute is used to locate elements with its location
Syntax:-
driver.findElement(By.xpath(“xxx”));
Example:
driver.findElement(By.xpath(“.//*[@id=‘Email’]”)).sendKeys(abc@dureka.co);
B y P a rti al L i n k Text B y CS SBy XPATH
34. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Commands To Locate Web Elements
This attribute is used to locate elements with its style properties
Syntax:-
driver.findElement(By.css(“xxx”));
Example:
driver.findElement(By.cssSelector(“#next”)).click();
B y N a m e B y C l a s s N ame B y Ta g N a m e B y L i n k Tex tB y I D B y P a rti al L i n k Text By CSSB y X PATH
35. www.edureka.co/testing-with-selenium-webdriverEDUREKA’S SELENIUM CERTIFICATION TRAINING
Course Details & Customer Reviews
Go to www.edureka.co/testing-with-selenium-webdriver
Get Edureka Certified in Selenium Today!
Radha Muthian says, “I learned Selenium WebDriver and the course
was very helpful to automate the Web Applications. The lifetime
access of classes helps a lot to refer back and download the codes.”
Vijay Krishnan says, “I have attended Selenium Web driver Certification with
Edureka. The trainer has explained all the concepts of the course in detail
manner which was very easy to understand. Worth for the money spent!!!!”
Tom Tully says, “I wanted to learn Selenium Webdriver in a live, real
course, not self paced, so there would be pressure on me to finish.
Edureka accomplished this at a price far lower than an in-person class,
and as far as I know they are the only internet class that has live lectures
on this subject. Teacher was very knowledgeable. I learned basic use of
Selenium. No problem with me being in US and teacher in India. They
have US 800 number.”
Suhas Kashyap says, “The online Course(Selenium Webdriver), which
I took from Edureka was interactive and also helped me to improve
my knowledge on selenium. Further helped me in changing the job as
well. Thanks Edureka Team... :).”
Well, there are multiple reasons. Here are few in no particular order
Webdriver offers a cleaner API than selenium RC. The most common example is you have selenium.type and selenium.typeKeys, both does the same thing in effect. Webdriver offers just one method sendKeys for all type related action. In short you can say, webdriver classes are better organized?
Selenium works using javascript injection. If you have worked with selenium for sometime, then you must be aware of the same origin policy issues and limitations of javascript injection. Webdriver overcomes this by using a driver for each browser. For firefox this means, webdriver attaches itself to browser as an addon, for IE it uses automation atoms and for chrome and opera it uses the chrome driver.
Due to the above mentioned reason, webdriver tests are faster than Selenium
Its much easier to extend webdriver compared to selenium. Webdriver provides extendable action classes which you can combine and create your own customized actions.
Webdriver can support testing in mobile devices such as Iphone, ipad and android phones and tablets.
Last but not at all the least, there is no development work happening in selenium project now. Whatever is available now, will continue to be supported but no new methods or enhancements are happening for selenium. Selenium and webdriver projects were merged some years back and became Selenium 2.0
You can find additional details about webdriver here and reason for merger here
Well, there are multiple reasons. Here are few in no particular order
Webdriver offers a cleaner API than selenium RC. The most common example is you have selenium.type and selenium.typeKeys, both does the same thing in effect. Webdriver offers just one method sendKeys for all type related action. In short you can say, webdriver classes are better organized?
Selenium works using javascript injection. If you have worked with selenium for sometime, then you must be aware of the same origin policy issues and limitations of javascript injection. Webdriver overcomes this by using a driver for each browser. For firefox this means, webdriver attaches itself to browser as an addon, for IE it uses automation atoms and for chrome and opera it uses the chrome driver.
Due to the above mentioned reason, webdriver tests are faster than Selenium
Its much easier to extend webdriver compared to selenium. Webdriver provides extendable action classes which you can combine and create your own customized actions.
Webdriver can support testing in mobile devices such as Iphone, ipad and android phones and tablets.
Last but not at all the least, there is no development work happening in selenium project now. Whatever is available now, will continue to be supported but no new methods or enhancements are happening for selenium. Selenium and webdriver projects were merged some years back and became Selenium 2.0
You can find additional details about webdriver here and reason for merger here
Selenium RC injects javascript function into browsers when the web page is loaded.
Selenium WebDriver drives the browser using browser's built-in support.