This is what I wrote below. I am using PyCharm 2022.2.2 (Community Edition)
Build #PC-222.4167.33, built on September 15, 2022
from selenium import webdriver
# Chrome driver = Path
#to open an URL in a BROWSER
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
name = "Trainer"
service_obj = Service(r"C:\Users\DS-02\Desktop\Manjit\chromedriver.exe") #---- doesn't works
driver = webdriver.Chrome(Service = service_obj)
The error which I am getting is below:
C:\Users\DS-02\AppData\Local\Programs\Python\Python310\python.exe C:\Users\DS-02\Desktop\Manjit\PythonSelenium\Class_1_demo_Browser.py
Traceback (most recent call last):
File "C:\Users\DS-02\Desktop\Manjit\PythonSelenium\Class_1_demo_Browser.py", line 10, in <module>
driver = webdriver.Chrome(Service = service_obj) #----- doesn't works
TypeError: WebDriver.__init__() got an unexpected keyword argument 'Service'
Please help,
Thanks and regards
I have tried the code below and works sometime now it doesn't works. I want to fix the code above:
#driver = webdriver.Chrome(executable_path = service_obj) #driver = webdriver.Chrome(executable_path = '../Webdriver/chromedriver.exe')
Please help
CodePudding user response:
You need to change this line driver = webdriver.Chrome(Service = service_obj)
to be
driver = webdriver.Chrome(service = service_obj)
Parameter to be passed into webdriver.Chrome()
in order to initialize driver
object should be lowercased service while Service in your code is this:
selenium.webdriver.chrome.service
, you called it Service
here:
from selenium.webdriver.chrome.service import Service
CodePudding user response:
This error message...
TypeError: WebDriver.__init__() got an unexpected keyword argument 'Service'
...implies that when the program execution starts the int()
method counters an unexpected keyword argument 'Service'.
Details
With the availability of selenium4 the key executable_path()
is deprecated and you have to use the key service
.
However you need to take care of couple of things as follows:
Incase you use the
service
keyword you have to create aService
object and assign the absolute location of the ChromeDriver, you have to import:from selenium.webdriver.chrome.service import Service
The keyword within
webdriver.Chrome()
isservice
. So you have to:service_obj = Service('C:\\Users\DS-02\\Desktop\\Manjit\\chromedriver.exe') driver = webdriver.Chrome(service = service_obj)