Reputation: 11
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?
Cleared cache (before this deleted previous pycharm project folder), Windows 10 OS
Installed Python 3.11.3
Installed Pycharm community edition b 2023.1.3 231.9161.41
Launched pycharm terminal. (it showed (env) .. prompt automatically.
here ran pip install selenium
, it passed
closed and relaunched Pycharm
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
Reputation: 15556
With the new Selenium Manager, drivers will be automatically downloaded to the ~/.cache/selenium
folder unless any of these conditions are met:
Service
classPATH
Environment VariableSo 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
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
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. google-chrome, firefox or microsoft-edge 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
.
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
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
Reputation: 23
Webdriver is in the PATH?
Might help (says that the path is Optional argument): [https://chromedriver.chromium.org/getting-started]
Upvotes: 0