0

What is the main Difference between :

Webdriver wd= new ChromeDriver();​

and

ChromeDriver wd= new ChromeDriver();​

I know that ChromeDriver is a class which extends the RemoteWebDriver which in turn implements the WebDriver Interface. What I want to know is why the later won't work?

cruisepandey
  • 26,802
  • 6
  • 16
  • 37
  • Before asking the question on stackoverflow it is very much appreciated if you searched for the possible solution. – Alok May 09 '18 at 04:19
  • 1
    What is your question? what is the difference or why `ChromeDriver` won't work? if it's the second one you need to explain what *won't work* means exactly. – Guy May 09 '18 at 04:41

2 Answers2

0

In terms of Java, WebDriver is not a "type". It is an Interface. You cannot use construction like WebDriver webDriver = new WebDriver(); since WebDriver, as an interface, just declares which methods have to be supported in classes which implement that interface. You cannot invoke methods of WebDriver just because they have not yet been implemented.

ChromeDriver "implements" the interface WebDriver (more precisely it extends RemoteWebDriver which, in turn, implements interface WebDriver). So you can create an object of ChromeDriver type.

cruisepandey
  • 26,802
  • 6
  • 16
  • 37
Ramesh Korla
  • 31
  • 2
  • 3
  • 7
0

Have you ever given a thought why do you declare a list of WebElement like this :

List<WebElement> ele = driver.findElements(By.xpath("some Xpath "));

instead of ArrayList<WebElement> or LinkedList<WebElement>

Because we want to have some specific ready mate methods which would be applicable for our list.

Either way we can invoke chrome browser , I do not know why you have mentioned
the later won't work? -- It should work.

You may some times want to go with ChromeDriver class when you have some special requirement like : Invocation of constructor and some of the methods like :

        driver.executeAsyncScript(script, args);
        driver.executeScript(script, args);
        driver.findElementByClassName(using);
        driver.findElementByCssSelector(using);
        driver.findElementById(using);
        driver.perform(actions);
        driver.setLocation(location);
        driver.getCapabilities();
        driver.getErrorHandler();
        driver.getFileDetector();
        driver.getMouse();
        driver.getKeyboard();

and so many..

cruisepandey
  • 26,802
  • 6
  • 16
  • 37
  • If this solution has helped you resolved your issue , you can close it by checking the check mark sign that is just under the downvote button , and beside my answer ! – cruisepandey May 10 '18 at 08:37