Introduction to Selenium WebDriver – Selenium Tutorial # 8

Tram Ho

In the previous articles, we focused on Selenium IDE and its various aspects. We have explored the tool and discussed its features. We have also built several scripts that use Selenium IDE and Firebug; thereby moving to the different types of web elements available and their positioning strategies.

Now that we have mastered the Selenium IDE, we will move our learning to creating more advanced automation scripts using Selenium WebDriver – one of the most compelling automated testing tools. Here, let’s discuss in detail.

Overview of Selenium WebDriver

WebDriver is one of the most powerful and popular tools of the Selenium toolkit. WebDriver is an extended version of Selenium RC with outstanding advantages and solve many limitations of Selenium RC. WebDriver extends support for many of the latest browsers and platforms, unlike Selenium IDE. WebDriver also does not require the Selenium server to be started before executing test scripts, unlike Selenium RC.

Selenium RC combines with WebDriver API to create Selenium 2.0. Selenium has been developed to support dynamic web pages and Ajax calls. It also supports various drivers to perform web-based mobile tests.

Architecture of WebDriver

WebDriver is a web-based testing tool with subtle differences from Selenium RC: WebDriver is built on the basis of an independent client created for each web browser; No heavy JavaScript required.

WebDriver makes calls directly to the Web browser and the entire test script is done in this fashion. WebDriver can be used with supported browsers and has automation capabilities.

Unlike Selenium RC, Selenium WebDriver basically does not require Selenium Server to be started before launching test script execution. Users can use this utility to request or not to Selenium Server when they are performing tests on the same machine where the browser resides (the same client).

Some special cases require Selenium Server for WebDriver:

  • When users want to execute test scripts on a remote machine.
  • When users want to execute test scripts on HtmlUnit Driver.
  • When users want to execute test scripts on multiple platforms.

WebDriver is a completely object-oriented framework, operating on the OS layer (operating system layer). It uses the browser’s native compatibility to automate without using any peripheral entities. With increasing demand, WebDriver has become very popular, its user base is large and has by far become one of the most widely used open source automation testing tools.

Selenium WebDriver features

Browser Compatibility

WebDriver supports a wide range of web browsers and their versions. Unlike Selenium RC and Selenium IDE, WebDriver supports all common browsers, in addition there are some unique and rare browsers such as HtmlUnit browser.

HtmlUnit browser executes test scripts similar to other browsers except for the fact that it runs in headless mode, which means that it has no GUI and the user cannot see / observe the process. Execute test script. Because the execution of the test script occurs in headless mode, the execution speed will be very quick.

WebDriver also supports web-based mobile testing. It provides AndroidDriver and IphoneDriver to backup mobile web-based test.

Language Support

In previous articles we learned how to create scripts using the record and playback function, how to create them manually using Selenese statements. While creating such test scripts, we will encounter some limited difficulties. Such as below.

Some limitations in Selenium IDE:

  • No support for iteration statements and conditional statements.
  • No support for loops.
  • Does not support error handling.
  • Does not support dependency test scripts.

The above obstacles can cause problems in the program. To improve this, WebDriver facilitates users to choose one of the different programming languages ​​and thereby build their test script in the specified language.

Programming languages ​​supported by Selenium WebDriver:

  • Java
  • C #
  • PHP
  • Pearl
  • Ruby
  • Python

Therefore, users can choose any programming language (as long as WebDriver is supported) based on their capabilities and can begin to build test scripts.


When compared to other Selenium tools, WebDriver is the fastest of all. WebDriver takes advantage of your browser’s native compatibility with automation; Therefore, communication does not need to be through any external intervention, instead WebDriver communicates directly with the browser like any user.

Other tools from the Selenium suite such as Selenium RC do not communicate directly with the web browser. The client libraries (test scripts written in any programming language) communicate with Selenium Remote Control Server, Remote Control communicates with a Selenium Core (JavaScript Program) from which to communicate with the web browser. . Therefore, this kind of twisted communication result is an obstacle in the execution speed.

Drivers, Methods and Classes

WebDriver provides a range of solutions to some of the potential challenges in Automated Testing. It helps us handle complex types of web elements like checkboxes, dropdowns, alerts, etc. with the help of dynamic search engines.

With the advent of the mobile era, the WebDriver API has also matured and introduced a number of key technologies (the key) to this horizon. WebDriver allows users to perform web-based mobile testing. It provides two drivers needed to perform web-based mobile testing:

  • AndriodDriver (for Android mobile phones)
  • IphoneDriver (for iOS mobile line)

Moreover, WebDriver API is quite simple and easy to use. It does not include repeated commands. In contrast, Selenium RC embodies many tautological statements (a tautological – a formula or assertion that is always true in every possible explanation: “x = y or x ≠ y” . Example: “The whole ball is red or the ball is not red. “This is always true regardless of the color of the ball.)


In this tutorial, the author tried to familiarize you with Selenium WebDriver by outlining its architecture, features, and limitations.

Here are the main points of this article:

  • Selenium consists of 4 basic components: Selenium IDE, Selenium RC, WebDriver, Selenium Grid.
  • WebDriver allows users to perform automated web-based testing. WebDriver is a completely different tool and has superior advantages compared to Selenium RC.
  • WebDriver supports many web browsers, programming languages ​​and testing environments.
  • WebDriver communicates directly with the web browser and uses its own compatibility for automated testing.
  • WebDriver’s support is not limited to the peripheral activities of traditional users. Instead, it supports efficient handling mechanisms for complex user actions such as dropdown processing, Ajax calling, window switching, navigation, alert handling, etc.
  • WebDriver allows users to perform web-based mobile tests. For similar support, WebDriver introduces AndroidDriver and IphoneDriver.
  • WebDriver is faster than other Selenium Suite tools because it makes a call directly to the browser without any external intervention.

The above translation may also contain errors, if you are interested can see the original article here:

Thank you for watching and see you in the next post ?

Chia sẻ bài viết ngay

Nguồn bài viết : Viblo