From SeleniumSelenium's perspective, the WebDriver InterfaceWhat is the difference between ChromeDriver and WebDriver in selenium? interface is similar like a agreement which the 3rd party Browser Vendors like Mozilla, Chrome, Internet Explorer, Safari, etc have to adhere and implement the same. This would in-turn help the end-users to use the exposed APIs to write a common code and implement the functionalities across all the available Browsersbrowsers without any change.
Through WebDriver driver = new FirefoxDriver(); wethe line of code:
WebDriver driver = new FirefoxDriver(); We are creating an instance of the WebDriver Interface interface and casting it to FirefoxDriver ClassFirefoxDriver class. All the Browser Drivers like FirefoxDriver, ChromeDriver, InternetExplorerDriver, PhantomJSDriver, SafariDriver etc implemented the WebDriver interface (actually the RemoteWebDriver class implements WebDriver InterfaceWebDriver Interface and the Browser Driversbrowser drivers extends RemoteWebDriverRemoteWebDriver). So if we use WebDriver driver, then we can use the already initialized driverdriver instance (as common object variable) for all browsers we want to automate e.g. Mozilla, Chrome, InternetExplorer, PhantomJS, Safari.
A WebElementWebElement is an abstraction used to identify the Element nodes and are simply known as elements when it is transported via the protocol, between remote and local ends. The web element identifier is the string constant expressed as: