This document provides an introduction and overview of Selenium WebDriver. It discusses what WebDriver is, the programming languages it supports, and how it compares to the previous Selenium RC tool. It also provides step-by-step instructions on how to install WebDriver and create a simple test script in Java using the Eclipse IDE. Finally, it covers how to access forms, links, tables, perform keyboard/mouse actions, and upload files using WebDriver.
2. Introduction to WebDriver & Comparison with
Selenium RC
What is WebDriver?
WebDriver is a web automation framework that allows you to execute your tests against
different browsers, not just Firefox (unlike Selenium IDE).
• WebDriver also enables you to use a programming language in creating your test scripts (not
possible in Selenium IDE).
• You can now use conditional operations like if-then-else or switch-case
• You can also perform looping like do-while.
3. Following programming languages are supported by WebDriver
• Java
• .Net
• PHP
• Python
• Perl
• Ruby
• You do not have to know all of them. You just need to be knowledgeable in one. However, in
this tutorial, we will be using Java with Eclipse as our IDE
4. WebDriver Vs Selenium RC
• Before the advent of WebDriver in 2006, there was another, automation tool called Selenium
Remote Control. Both WebDriver and Selenium RC have following features:
• They both allow you to use a programming language in designing your test scripts.
• They both allow you to run your tests against different browsers.
5. Guide to install Selenium WebDriver
Step 1 - Install Java on your computer
• Download and install the Java Software Development Kit (JDK)
• This JDK version comes bundled with Java Runtime Environment (JRE) so you do not need
to download and install the JRE separately.
Step 2 - Install Eclipse IDE
• Download "Eclipse IDE for Java Developers" here. Be sure to choose correctly between
Windows 32 Bit and 64 Bit versions.
Step 3 - Download the Selenium Java Client Driver
• You can download the Selenium Java Client Driver here. You will find client drivers for other
languages there, but only choose the one for Java.
6. • Step 4 - Configure Eclipse IDE with WebDriver
• Launch the "eclipse.exe" file inside the "eclipse" folder that we extracted in step 2. If you
followed step 2 correctly, the executable should be located on C:eclipseeclipse.exe.
• When asked to select for a workspace, just accept the default location.
• Create a new project through File > New > Java Project. Name the project as "newproject".
A new pop-up window will open enter details as follow
• Project Name
• Location to save project
• Select an execution JRE
• Select layout project option
• Click on finish button
7. 4. In this step,
• Right-click on the newly created project and
• Select New > Package, and name that package as "newpackage".
A pop-up window will open to name the package,
• Enter the name of the package
• Click on finish button
5. Create a new Java class under newpackage by right-clicking on it and then selecting- New >
Class, and then name it as "MyClass". Your Eclipse IDE should look like the image below.
6. Add all the JAR files inside and outside the "libs" folder. Your Properties dialog should now
look similar to the image below.
7. Finally, click OK and we are done importing Selenium libraries into our project.
8. Creating your First Script in Webdriver
Using the Java class "myclass" that we created in the
previous tutorial, let us try to create a WebDriver script that
would.
• fetch Mercury Tours' homepage
• verify its title
• print out the result of the comparison
• close it before ending the entire program.
9. Accessing Forms using Selenium WebDriver
Accessing Form Elements
• Input Box
Input boxes refer to either of these two types:
Text Fields- text boxes that accept typed values and show them as they are.
Password Fields- text boxes that accept typed values but mask them as a series of special
characters (commonly dots and asterisks) to avoid sensitive values to be displayed.
10. Accessing Links & Tables using Selenium Webdriver
Accessing Links
Links Matching a Criterion
• Links can be accessed using an exact or partial match of their link text. The examples below
provide scenarios where multiple matches would exist, and would explain how WebDriver
would deal with them.
Exact Match
• Accessing links using their exact link text is done through the By.linkText() method. However,
if there are two links that have the very same link text, this method will only access the first
one. Consider the HTML code below
Partial Match
• Accessing links using a portion of their link text is done using the By.partialLinkText() method.
If you specify a partial link text that has multiple matches, only the first match will be
accessed. Consider the HTML code below.
11. Keyboard Mouse Events , Uploading Files -
Webdriver
Handling Keyboard & Mouse Events
Handling special keyboard and mouse events are done using the Advanced User
Interactions API. It contains the Actions and the Action classes that are needed when executing
these events.
12. In the following example, we shall use the moveToElement() method to mouse-over on one
Mercury Tours' table rows.
Step 1
• Import the Actions and Action classes.
• Keyboard Mouse Events , Uploading Files - Webdriver
Step 2
• Instantiate a new Actions object.
• Keyboard Mouse Events , Uploading Files - Webdriver
13. Step 3
Instantiate an Action using the Actions object in step 2.
Keyboard Mouse Events , Uploading Files - Webdriver
In this case, we are going to use the moveToElement() method because we are simply going to
mouse-over the "Home" link. The build() method is always the final method used so that all the
listed actions will be compiled into a single step.
Step 4
• Use the perform() method when executing the Action object we designed in Step 3.
14. Conclusion
• In this presentation, I have giv en the introduction of
webdriver and explained about comparison of selenium
RC.
• Further topics will be expain in nest presentation.
• If you are interested to join in the training reach us-
8122241286
• Visit us-http://thecreatingexperts.com/selenium-training-
in-chennai/