Selenium Webdriver

Selenium Webdriver

Last updated on 19th Sep 2020, Artciles, Blog

About author

Kannan (Sr Technical Project Manager )

He is a TOP-Rated Domain Expert with 6+ Years Of Experience, Also He is a Respective Technical Recruiter for Past 3 Years & Share's this Informative Articles For Freshers

(5.0) | 17344 Ratings 360

Selenium WebDriver is a collection of open source APIs which are used to automate the testing of a web application.

Selenium WebDriver tool is used to automate web application testing to verify that it works as expected. It supports many browsers such as Firefox, Chrome, IE, and Safari. However, using the Selenium WebDriver, we can automate testing for web applications only. It does not qualify for window-based applications. It also supports different programming languages such as C#, Java, Perl, PHP and Ruby for writing test scripts. Selenium Webdriver is platform-independent since the same code can be used on different Operating Systems like Microsoft Windows, Apple OS and Linux. It is one of the components of the selenium family, which also includes Selenium IDE, Selenium Client API, Selenium Remote Control and Selenium Grid.

Selenium WebDriver does not handle window components, but this limitation can be overcome by using external tools such as AUTO IT tool, Sikuli etc. It has different location strategies as well such as ID, Name, Link text, Partial link text, Class name, CSS selector and Xpath. It also has better support for dynamic web pages like Ajax, where elements of the web page may change without the page itself being reloaded. By using different jar files, we can also test API, Database Test etc. using Selenium WebDriver.

Subscribe For Free Demo
[contact-form-7 404 "Not Found"]

Selenium WebDriver Architecture

pasted image 0 (3)

Fig: Selenium WebDriver Architecture

Selenium test script – Selenium test script is the test code written in any of the mentioned programming languages that are interpreted by the driver 

JSON Wire Protocol – JSON Wire Protocol provides a transport mechanism to transfer data between a server and a client. JSON Wire Protocol is the industry standard for various web services

Browser drivers – Selenium uses drivers, specific to each browser to establish a secure connection with the browser

Browsers – Selenium WebDriver supports multiple web browsers to test and run applications on.

Benefits of Selenium WebDriver

  • Selenium WebDriver supports seven programming languages: Java, C#, PHP, Ruby, Perl, Python, and .Net.
  • It supports cross-browser interoperability that helps you perform testing on various browsers like Firefox, Chrome, IE, Safari, etc.
  • Tests can be performed on different operating systems: Windows, Mac, Linux, Android, and iOS.
  • Selenium WebDriver overcomes limitations of Selenium v1 like file upload, download, pop-ups, and dialog barrier

1.Selenium Client Libraries

Developers and Software testers use the language they are comfortable with to write automation scripts. There are various languages available like C#, Java, Python, Perl, etc in which one can write a script, so this can make the task difficult. However, Selenium client library or Selenium language binding facilitates the capability of multi-language support. You can use the language you are comfortable with to write your automation script and Selenium will do the rest. To understand this more, let’s take an example if you want to write automation script in PHP language, you would require PHP client libraries and the rest of the task will be done. You can download all the Selenium binding from Selenium official website.

2.JSON Wire Protocol

JSON (JavaScript Object Notation) Wire Protocol facilitates the capability of transferring the data between the Client and Server on the web. It is a REST (Representational State Transfer) API which provides a transport mechanism and defines a RESTful web service using JSON over HTTP.

3.Browser Drivers

Browser Drivers are used for interacting with browsers and relaying automation script instructions to the browsers. Browser drivers take care of loss of any internal logic of browser functionalities. Each browser has its specific Browser Webdriver.

Following are the steps involved in running automation script using specific Browser driver:

    1. 1.HTTP request gets generated for every Selenium command and sent to browser driver.
    2. 2.Specific browser driver receives the HTTP request through the HTTP server.
    3. 3.HTTP Server sends all the steps to perform a function which are executed on the browser.
    4. 4.Test execution report is sent back to server and HTTP server sends it to the Automation script.

4.Browsers

The best part about Selenium Webdriver is that it supports all the major browsers like Google Chrome, Mozilla Firefox, Internet Explorer and Safari. Every browser has specific Webdriver for executing automation scripts.

Types of Browser specific Web Drivers

There are various drivers like HtmlUnit driver, Chrome Driver, Firefox driver, Internet Explorer Driver, Opera Driver which are required in order to run automation scripts. Let’s get to learn each one of them in detail:

1.HtmlUnit Driver

As the name suggests, this is based upon HtmlUnit and is one of the most lightweight and fast implementations of WebDriver. If you’re using a language binding (other than Java) in that case, you’ll need to have this driver.

Command lines to use in your code for using HtmlUnit Driver:

java

  • WebDriver driver = new HtmlUnitDriver();

csharp

  • IWebDriver drivernewRemoteWebDriver(newUri(“http://127.0.0.1:4444/wd/hub”),
  • DesiredCapabilities.HtmlUnit());

python

  • driver=webdriver.Remote(“http://localhost:4444/wd/hub”, webdriver.DesiredCapabilities.HTMLUNIT.copy())

ruby

  • driver=Selenium::WebDriver.for:remote, :url=>”http://localhost:4444/wd/hub”,:desired_capabilities=> :htmlunit

perl

  • my $driver = Selenium::Remote::Driver->new(browser_name => ‘htmlunit’, remote_server_addr => ‘localhost

2.Firefox Driver

As the name suggests, Firefox Driver is used to control firefox browser while running automation script.

Commands to use in your code for using Firefox Driver:

java

  • WebDriver driver = new FirefoxDriver();

csharp

  • IWebDriver driver = new FirefoxDriver();

python

  • driver = webdriver.Firefox()

ruby

  • driver = Selenium::WebDriver.for :firefox

perl

Course Curriculum

Learn Selenium WebDriver Training to Advance Your Career

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum
  • my $driver = Selenium::Remote::Driver->new;

3.Internet Explorer Driver

Internet Explorer Driver is used to run automation scripts on internet explorer. It supports IE7,8,9,10, and 11. Earlier it used to support IE6 as well however it dropped supported for it in 2014.

Command lines to use in your code for using Internet Explorer Driver:

java

  • WebDriver driver = new InternetExplorerDriver();

csharp

  • IWebDriver driver = new InternetExlorerDriver();

python

  • driver = webdriver.Ie()

ruby

  • driver = Selenium::WebDriver.for :ie

perl

  • my $driver = Selenium::Remote::Driver->new(browser_name => ‘internet explorer’);

4.ChromeDriver

Chrome Driver works with Chrome Browser to help automate test automation scripts. For the WebDriver to discover ChromeDriver, you need to enter ChromeDriver’s path into the test script.

Command lines to use in your code for using ChromeDriver:

java

  • WebDriver driver = new ChromeDriver();

csharp

  • IWebDriver driver = new ChromeDriver();

python

  • driver = webdriver.Chrome()

ruby

  • driver = Selenium::WebDriver.for :chrome

perl

  • my $driver = Selenium::Remote::Driver->new(browser_name => ‘chrome’);

Features of Selenium Webdriver

We know that Selenium WebDriver is one of the best choices for developers and we need to understand what makes it stand out of the crowd. Let’s have a look at some of the top features of Selenium WebDriver:

Multi-Browser Compatibility

Selenium Webdriver interacts with the website and its web elements in a browser just like a real user with use of browser’s native support to hit direct calls without the need of any intermittent software or device. It supports all modern web browsers like Chrome, Firefox, Opera, Safari and Internet Explorer. You can launch any browser with easy commands. For example Chrome Browser

WebDriver driver = new ChromeDriver();

Selenium web driver also supports AndroidDriver, HtmlUnitDriver, and IPhoneDriver.

1570190913nxeq3wJKgz (1)

Multiple Language Support

It supports most of the commonly used programming languages like Java, Javascript, Python, PHP, Ruby, C#, Perl etc. It provides us the freedom to choose any of the programming languages to write our automation scripts.

It also allows using more efficient way of writing automation scripts like using the switch statement, conditional statements, decision making statements to strengthen the automation script and make capable of handling all the situations.

Speed Speed and Performance

Selenium Webdriver executes test script faster when compared to the other tools of the Selenium suite. Unlike Selenium RC, it directly communicates with the browser without the need of any intermediate server.

1570190913E3tlUnZREd

1.Better Handling of Dynamic Web Elements

Handling dynamic web elements is one of the most common challenges while performing automation testing. Selenium Webdriver knows how to handle dynamic web elements better like checkboxes, dropdowns, and alerts etc. It is very easy to locate the web elements with XPath or ID in case of static elements, but if the element’s XPath or ID keeps changing, it becomes very difficult to handle.

Selenium uses some of the following methods to handle dynamic elements:

    1. 1.Absolute XPath: This is the most often used Xpath to handle dynamic elements and it contains the complete path of the web UI element starting from the root node.
    2. 2.Contains(): This function has the ability to find an element with partial text and can be used to handle dynamic elements.
    3. 3.Starts-with(): This function is based on finding and matching the starting text of the supplied attribute with the attribute of dynamic elements.
Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

2.Easy to Identify and Use Web Elements

Selenium WebDriver has a set of locators that can be helpful in finding web elements on the webpage. With this, it becomes easier to implement those elements in the test automation suite. Following are the few most used locators:

  • Name
  • ClassName
  • ID
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM
  • Detailed test reports cannot be generated.
  • Testing images is not possible.

No matter what, these shortcomings can be overcome by integrations with other frameworks. That is, for testing images Sikuli can be used, and for generating detailed test reports, TestNG can be used.

The advantages  WebDriver has over RC are:

  • Support for more programming languages, operating systems, and web browsers
  • Ability to overcome the limitations of Selenium v1
  • Simpler commands when compared to RC, and a better API
  • Support for batch testing, cross-browser testing, and data-driven testing

The drawback WebDriver has when compared to RC is that test reports cannot be generated in WebDriver; whereas, RC generates detailed reports.

Are you looking training with Right Jobs?

Contact Us

Popular Courses