1

when we create an object of Chrome Class using a code:

#Creating an instance of Chrome class of webdriver module
Chrome_class_object = webdriver.Chrome()

#Printing an Output
print(type(Chrome_class_object))

Output:

<class 'selenium.webdriver.chrome.webdriver.WebDriver'>

we see in output that the object belongs to selenium.webdriver.chrome.webdriver.WebDriver class but not a Chrome class but we created it through Chrome class of webdriver so it should belong to Chrome Class. Why is that so?

Creating an instance of Chrome Class of webdriver module in selenium library

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
Ali Haider
  • 25
  • 4

2 Answers2

0

WebDriver is the interface, where as ChromeDriver implements the WebDriver class. Treat WebDriver as a contract with skeleton of the methods but without any body. The ChromeDriver/GeckoDriver can implement those methods as per their standards.

So you can't create an object of an interface and have to create it from the child class implementing the WebDriver interface. Hence when you:

Chrome_class_object = webdriver.Chrome()
print(type(Chrome_class_object))

The output is:

<class 'selenium.webdriver.chrome.webdriver.WebDriver'>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

The WebDriver class is a generic class that acts as a base for different browser-specific implementations, such as Chrome, Firefox, Edge, etc. Each browser-specific implementation extends the WebDriver class and provides its own unique functionality and methods.

In the case of webdriver.Chrome(), the Chrome class is a subclass of WebDriver specifically tailored for controlling the Chrome browser. It inherits all the methods and properties of the WebDriver class and adds additional functionality specific to Chrome.

So, when you print the type of the Chrome object, it shows selenium.webdriver.chrome.webdriver.WebDriver, indicating that the object belongs to the WebDriver class for Chrome.

Even though you created the instance using the Chrome class, the type of the object reflects the underlying implementation class, which is the WebDriver class for Chrome.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24