I am using sublime to code python scripts. The following code is for selenium in python to install the driver automatically by using the webdriver_manager package
# pip install webdriver-manager from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By driver = webdriver.Chrome(ChromeDriverManager().install()) driver.maximize_window() #s=Service(path) #driver=webdriver.Chrome(service=s) driver.get('https://www.google.com') driver.find_element(By.NAME, 'q').send_keys('Yasser Khalil')
The code works fine but I got a warning like that
Demo.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(ChromeDriverManager().install())
How to fix such a bug?
internal package, is deprecated in Selenium 4. The changes are internal to the Selenium framework. Therefore, Selenium users can continue using the FindElement(By) and FindElements(By) as used in Selenium 3.
C:\python36>pip install -U selenium The <pip> tool will download the latest version of the Selenium package and install it on your machine. The optional –U flag will upgrade the existing version of the installed package to the latest version. Hope this Helps!!
DeprecationWarning: executable_path has been deprecated, please pass in a Service object ...implies that the keyexecutable_pathwill be deprecated in the upcoming releases. This change is inline with the Selenium 4.0 Beta 1changelogwhich mentions:
What is DeprecationWarning: executable_path has been deprecated, please pass in a Service object? Let us take a simple example to demonstrate the issue. In Selenium 4, the key executable_path is deprecated, and instead, we need to use an instance of the Service () class along with ChromeDriverManager ().install () command.
DeprecationWarning: executable_path has been deprecated, please pass in a Service object means that the key executable_path will be deprecated in the upcoming releases. Once the key executable_path is deprecated you have to use an instance of the Service () class as follows:
DeprecationWarning: executable_path has been deprecated, please pass in a Service object ...implies that the keyexecutable_pathwill be deprecated in the upcoming releases.
I could figure it out
# pip install webdriver-manager from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By s=Service(ChromeDriverManager().install()) driver = webdriver.Chrome(service=s) driver.maximize_window() driver.get('https://www.google.com') driver.find_element(By.NAME, 'q').send_keys('Yasser Khalil')
This error message...
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
...implies that the key executable_path
will be deprecated in the upcoming releases.
This change is inline with the Selenium 4.0 Beta 1 changelog which mentions:
Deprecate all but
Options
andService
arguments in driver instantiation. (#9125,#9128)
With selenium4 as the key executable_path
is deprecated you have to use an instance of the Service()
class along with ChromeDriverManager().install()
command as discussed below.
Ensure that:
Selenium is upgraded to v4.0.0
pip3 install -U selenium
Webdriver Manager for Python is installed
pip3 install webdriver_manager
You can find a detailed discussion on installing Webdriver Manager for Python in ModuleNotFoundError: No module named 'webdriver_manager' error even after installing webdrivermanager
from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) driver.get("https://www.google.com")
Console Output:
[WDM] - ====== WebDriver manager ====== [WDM] - Current google-chrome version is 96.0.4664 [WDM] - Get LATEST driver version for 96.0.4664 [WDM] - Driver [C:\Users\Admin\.wdm\drivers\chromedriver\win32\96.0.4664.45\chromedriver.exe] found in cache
You can find a detailed discussion on installing Webdriver Manager for Python in Selenium ChromeDriver issue using Webdriver Manager for Python
Incase you want to pass the Options()
object you can use:
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager options = Options() options.add_argument("start-maximized") driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) driver.get("https://www.google.com")
You can find the relevant Bug Report/Pull Request in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With