i

Selenium Step By Step Guide

Introduction to WebDriver API

Now let's talk about more on the technical part of the WebDriver, which we can usually see while instantiating the browser driver classes. WebDriver is an Interface which gives us a rich set of features to work on web elements. We can create the object for any browser class by taking reference to the WebDriver interface.

WebDriver driver=new ChromeDriver();

Here driver object helps us to interact with the chrome browser and gives us the power to validate the web elements present in web pages in the chrome browser.

One important thing here is to notice that the WebDriver interface is being referenced while creating the object for the ChromeDriver class, which means the implementation of the WebDriver interface is done by ChromeDriver class.

In the same way, we can create objects for other web browser classes based on our requirements and can use the methods defined in the WebDriver interface.

When the user uses the "driver" object to check the browser commands, we see the same by putting a dot after the driver object in eclipse.

Here is the technical architecture view of WebDriver operations:

 

This architecture shows that WebDriver extends the SearchContext interface, and then RemoteWebDriver class implements the WebDriver interface. All the browser classes like ChromeDriver, FirefoxDriver, OperaDriver, EdgeDriver, and SafariDriver extends the RemoteWebDriver class.

Here we observe that RemoteWebDriver class implements JavaScriptExecutor and TakesScreenshot. This is how we can use javaScriptExecutor and screenshot feature in many places for doing selenium test scripting.

Below is the way to create an instance of the browser driver class with reference to the WebDriver interface in Selenium.

WebDriver driver=new ChromeDriver();

Once the driver object is obtained, we can play around the WebDriver commands to control the web pages. Since WebDriver extends the SearchContext interface, it uses findElement() and findElements() method to locate the elements on the web page.