Narendra Bhagwat
Narendra Bhagwat

Reputation: 11

Without copying chromedriver.exe manually, selenium-python script is working, is it not mandatory to copy it manually?

I am not copying chromedriver.exe manually but still script is working fine.

But, install steps says that copying chromedriver.exe is required and mandatory.

Is it optional in recent builds ? If not, how script is passing without copying this .exe?

  1. Cleared cache (before this deleted previous pycharm project folder), Windows 10 OS

  2. Installed Python 3.11.3

  3. Installed Pycharm community edition b 2023.1.3 231.9161.41

  4. Launched pycharm terminal. (it showed (env) .. prompt automatically.

  5. here ran pip install selenium, it passed

  6. closed and relaunched Pycharm

  7. tried following selenium-python script and its passing

    import time
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get("https://www.google.com/")
    time.sleep(5)
    driver.close()
    

Query: when chromedriver.exe is not copied manually (which is MUST), how script is passing and from where its getting chromedriver.exe?

Upvotes: 1

Views: 988

Answers (5)

Michael Mintz
Michael Mintz

Reputation: 15556

With the new Selenium Manager, drivers will be automatically downloaded to the ~/.cache/selenium folder unless any of these conditions are met:

  • The driver location isn't specified in a Service class
  • A 3rd party driver manager is not installed
  • No drivers exist in directories included in the PATH Environment Variable

So a command such as driver = webdriver.Chrome() does all the work for you now. If you still want to choose the location, you can pass in an executable_path into the service arg, like this:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='./chromedriver.exe')
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()

Upvotes: 0

yusuf
yusuf

Reputation: 193

A template you can use, if you want to maximize the window.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
# pip install webdriver_manager 
from webdriver_manager.chrome import ChromeDriverManager  


options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
             options=options)

Link for Webdriver Manager: here

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193258

With the in introduction of Selenium Manager using Selenium v4.6 and above you don't need to explicitly download ChromeDriver, GeckoDriver or any browser drivers as such.

You just need to ensure that the desired browser client i.e. , or is installed. Selenium Manager is the new tool that would help to get a working environment to run Selenium out of the box. Beta 1 of Selenium Manager will configure the browser drivers for Chrome, Firefox, and Edge if they are not present on the PATH.


Solution

As a solution you can simply do:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.google.com/")
time.sleep(5)
driver.quit()

Upvotes: 1

Shawn
Shawn

Reputation: 8508

That's correct. If you are using Selenium v4.6.0 or above, setting up the path of chromedriver.exe is not mandatory anymore.

New in-built tool in the selenium known as SeleniumManager will download and handle the browser drivers for you. However, if you want to use a specific chromedriver.exe for any reason, you can set the path and that driver will be used, if not Selenium will download and handle the driver.exe for you.

References:

Upvotes: 1

Eugene
Eugene

Reputation: 23

Webdriver is in the PATH?

Might help (says that the path is Optional argument): [https://chromedriver.chromium.org/getting-started]

Upvotes: 0

Related Questions