Driver in Selenium: To Path or Not to Path?

Introduction:

When navigating the world of Selenium for web automation, a frequent query arises: Must we explicitly define the path for the driver, or can we rely on predefined configurations? 

In this blog post, we explore two strategies - leveraging webdriver.ChromeOptions() and explicitly designating the path using `Service` - to discern the merits of each approach.

Method 1. Using predefined configurations:



  • Pros: Conciseness, convenience.
  • Cons: Browser should be is installed and added to system PATH. 



Method 2. Using driver explicitly:



  • Pros: The code is independent. No need to add the browser to system PATH.
  • Cons: Need to manually download the webdriver as well as the browser. 


Tip for CPython:

To download the webdriver automatically you can use webdriver_manager library:



Conclusion:

The choice between these methods depends on your specific requirements. 

  • If you are confident in the availability of the browser in the system path, choose the first method. 
  • If you want to have more independent code - the second snippet is yours!

Reader's Question:

What method do you prefer when working with Selenium, and why bother specifying the path when it can work without it?