Selenium Webdriver Interface & Classes Hierarchy

Profile picture for user devraj

Class hierarchy is basically, how classes are inter-related to each other in certain order.  An interface in the Java programming language is an abstract type that is used to specify a behavior that classes must implement.

In Selenium we have different interfaces and classes which are inter-related, if you will see below flowchart:

selenium webdriver interface and class hierarchy

Here we are using parallelogram symbol for an interface, rectangle for classes, yellow arrow for extends and black directional connecter for implements.

SearchContext Interface

SearchContext is a super or top most interface in WebDriver hierarchy. This interface consists of only two methods findElement​() and findElements(). This interface is extended by both WebDriver and WebElement interfaces. 

WebDriver Interface

WebDriver is a remote control interface that enables introspection and control of user agents (browsers). It extends SearchContext. The methods in this interface fall into three categories:

  1. Control of the browser itself
  2. Selection of WebElements
  3. Debugging aids

Key methods are get(String), which is used to load a new web page, and the various methods similar to findElement(By), which is used to find WebElements.

Currently, you will need to instantiate implementations of this interface directly. You write your tests against this interface so that you may "swap in" a more fully featured browser when there is a requirement for one. Most implementations of this interface follow W3C WebDriver specification.

WebDriver interface has multiple inner interfaces like ImeHandler, Navigation, Options, TargetLocator, Timeouts and Window which contains methods related to specific events.

RemoteWebDriver Class

RemoteWebDriver, which is a fully implemented class where all abstract methods of WebDriver and SearchContext interface implemented. Also, two other comment interfaces JavascriptExecutor and TakesScreenshot abstract methods are implemented in RemoteWebDriver class.

RemoteWebDriver also also implements few other interfaces like HasCapabilities, HasInputDevices, Interactive, PrintsPage and HasVirtualAuthenticator.

JavascriptExecutor Interface

JavaScriptExecutor is an Interface that helps to execute JavaScript through Selenium Webdriver. JavaScriptExecutor provides two methods "executescript" & "executeAsyncScript" to run javascript on the selected window or current page.

TakesScreenshot Interface

TakesSchreenshot capture a screenshot and store it in different ways.

Browser Specific Classes

Browser specific classes provides control on a browser and provides different methods to test browser. Browser specific driver classes which extend RemoteWebDriver:

  1. InternetExplorerDriver
  2. FirefoxDriver
  3. ChromiumDriver
  4. OperaDriver
  5. Safari Driver

Classes which extends ChromiumDriver are:

  1. ChromeDriver
  2. EdgeDriver