Selenium: How to resolve DeprecationWarning: executable_path has been deprecated + زیرنویس فارسی
Selenium: How to resolve DeprecationWarning: executable_path has been deprecated + زیرنویس فارسی
After updating selenium to version 4 (python), you may get this message in console. “DeprecationWarning: executable_path has been deprecated, please pass in a Service object”. In this video I’ve explained how to resolve it using Service object.
Here is the solution: ============ If you define ChromeDriver directly ============ from selenium import webdriver from selenium.webdriver.chrome.service import Service driver_service = Service(executable_path=“C:/chromedriver.exe”) driver = webdriver.Chrome(service=driver_service) driver.get(”http://google.com\“) =================================================
OR
============ If you’re Using ChromeDriverManager ============ from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service driver_service = Service(executable_path=ChromeDriverManager().install()) driver = webdriver.Chrome(service=driver_service) driver.get(”http://google.com\“) =================================================
Content
0.48 -> hi everyone if you have recently updated
2.879 -> selenium to version 4 or you have just
4.96 -> fresh installed it you have probably
7.12 -> noticed that the application warning
8.72 -> about chrome driver executable pass at
11.12 -> runtime this is because of the change
13.679 -> that has taken place in selenium 4 and
16.16 -> all the driver arguments accepted system
18.8 -> and options have been deprecated
21.68 -> so far you have either defined the
23.76 -> chrome driver directly in this way or
26.32 -> you have used the chrome driver manager
28.4 -> instead
29.519 -> to resolve it we should use system class
32.079 -> to define the chrome driver and pass it
34 -> to the driver so first we import this
36.32 -> class
38.079 -> from selenium
42.84 -> webdriver chrome
46.32 -> service
47.76 -> import service
49.68 -> and then we create an instance of this
51.68 -> class using the executable path
53.92 -> attribute so we can say
58.719 -> driver service for example equals
61.84 -> service
64.479 -> executable pass equals this is where is
66.88 -> my chrome driver that exe located so i
70 -> just copy here
73.2 -> paste here so
74.96 -> similarly you can using the chrome
77.2 -> driver manager install
80.159 -> so we can say
86.479 -> executable pass equals
88.159 -> chromedrivermanager.install
90.72 -> finally we define the driver using this
93.52 -> argument so
95.52 -> in a set of this way we should say let
98.24 -> me comment this out
100.72 -> okay
104.88 -> driver equals verb driver dot chrome
110.159 -> now
111.36 -> we should pass a service argument so
115.04 -> service equals
119.68 -> driver service now if i run the code
122.399 -> again you can see that there is no
124.399 -> deprecation warning at all
132.319 -> as you can see this error has been fixed