What is WebDriver interface & hierarchy of related interfaces and Classes

Monil Joshi
4 min readSep 24, 2021

--

In previous article we have seen Introduction to Selenium Web Driver. You can read this article here.

Introduction to Selenium Web Driver

In our script first line was


System.setProperty(“webdriver.chrome.driver”,”<ChromeDriver_Path>/chromedriver”);
WebDriver driver = new ChromeDriver();

First we set Chrome driver path as a system property. But what is WebDriver and why we initialise object of WebDriver as ChromeDriver and not WebDriver. Here WebDriver is an interface in Selenium We can not write

WebDriver driver = new WebDriver();

Here WebDriver is an interface. So we cannot write our code like above statement because we cannot create Object of an Interface.

When we say we are using tool called Selenium Web Driver. This webdriver interface is connected with different java classes and interfaces. Before understanding code we should understand hierarchy of classes and interfaces and how they are related to each others.

Here is the diagram of hierarchy of related classes and interfaces

Hierarchy of classes and interfaces

I will be explaining each interface and class.

  1. SearchContext interface: It is the topmost interface in the hierarchy. It has two methods declared in it findElement(), findElements(). This is super interface for WebDriver interface. As you can see in the diagram Webdriver interface extends SearchContext interface.
    If you referred my previous blog and have basic script with you. You can traverse through classes and interfaces by using Ctrl + Click on ChromeDriver class. In case of Mac you should use Cmd + Click
Super interface SearchContext

2. WebDriver : This interface extends SearchContext interface. This interface contains methods like close(), get(), getCurrentUrl(), quit(). This interface contains findElement() and findElements() inherited due to extending SearchContext class

WebDriver interface

If you open this WebDriver.java in Intellij or your IDE. You can there are some inner interfaces present inside this interface which contains methods to perform some action.

  1. Options: This interface is managing stuff you would do in a browser menu. This inner interface contains methods like addCookie(), deleteCookie(), deleteAllCookie().
InnerInterface Option

2. Timeouts: This interface is managing timeout behavior for WebDriver instances. This inner interface contains methods like implicitlyWait(), pageLoadTimeout()

InnerInterface Timeouts

3. TargetLocator: This interface is used to locate a given frame or window. This inner interface contains methods like frame()(Overloaded method), parentFrame()

InnerInterface TargetLocator

4. Navigation: This interface allows user to navigate w.r.t browser history. This inner interface contains methods like back(), forward(), refresh() method

InnerInterface Navigation

5. ImeHandler: This interface is managing input methods.This inner interface contains methods like getAvailableEngines(), getActiveEngine()

InnerInterface ImeHandler

6. Window: This interface is managing browser window actions. This inner interface contains methods like setSize(), maximize()

InnerInterface Window

RemoteWebDriver: This class implements interfaces WebDriver, JavaScriptExecutor, TakeScreenshot and many more interfaces. This class implements all the abstract methods declared in above interfaces

RemoteWebDriver Class

Next hierarchy contains all the browser’s specific classes like ChromeDriver(), FirefoxDriver(). These classes extends RemoteWebDriver

ChromeDriver Class

All these classes controls execution running on respective browsers.

--

--

Monil Joshi

I am having an 8+ years of experience in software testing. Working with Web, Mobile and API technologies. Visit my GIT https://github.com/monilj