UrbanPro
true

Learn Selenium from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why we declare WebDriver driver = new FirefoxDriver(); and not FirefoxDriver driver = new FirefoxDriver();

Srinivas K
23/11/2018 0 0

Here, List or WebDriver is an Interface - a contract or set of rules created for implementing class.
So, in Java, we cannot create an instance of an interface. ie
I cannot say List list = new List();
But classes can be instantiated. Hence,
FirefoxDriver fd= new FirefoxDriver(); and
ArrayList list=new ArrayList();
are meaningful because both are classes in Java.
Now, coming back to the same question. When we say FirefoxDriver fd= new FirefoxDriver(); or ArrayList list=new ArrayList();
It is nothing but using specific implementation. ArrayList or FirefoxDriver. If we have code like this, then in the future, if we want to switch to
other implementations of List or WebDriver then we need to modify our complete code as there is no guarantee that the rest of the code doesn't make use of methods specific to the particular class. However, if given like this:
List list = new ArrayList();
WebDriver driver = new FirefoxDriver();
It gives the flexibility to switch implementation any time with minimal rework.
For eg: changing ArrayList to LinkedList you can change the code to List list = new LinkedList(); from List list = new ArrayList();.

0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

Wait Handler implementation in WebDriver
public void waitForElementPresence(By by) { Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT); wait.until(ExpectedConditions.presenceOfElementLocated(by)); } ...

Difference between driver.close() and driver.quit () method
close () -By using this command, we can close the current browser or page. quit() - By using this command, we can shut down the web driver instance or destroy the web driver instance(Close all the windows).

How to toggle b/w windows in webdriver
getWindowHandles will provide us handles for all windows available. Set windows = driver.getWindowHandles(); Iterate through all windows and choose suitable window based on its title for (String window...

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

How to toggle b/w frames in webdriver
driver.switchTo().frame() method takes one of the three possible arguments: A number - Select a frame by its (zero-based) index. A name or ID - Select a frame by its name or ID. A previously found...
X

Looking for Selenium Classes?

The best tutors for Selenium Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Selenium with the Best Tutors

The best Tutors for Selenium Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more