Home > Blockchain >  AttributeError: module 'selenium.webdriver.chrome.webdriver' has no attribute 'Chrome
AttributeError: module 'selenium.webdriver.chrome.webdriver' has no attribute 'Chrome

Time:08-30

Can anyone suggest about it? I have tried reinstall of selenium pip, still the same. Below is the code and error in Pycharm:

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

# //Chrome driver

service_obj=Service("D:\\PYTHONWITHSELENIUMTESTING\\Chromedriver\\chromedriver.exe")
#driver = webdriver.Chrome(Service=service_obj)
#driver.get("https://www.youtube.com/")

driver = webdriver.Chrome(executable_path = service_obj)

Error:

C:\Users\scdee\AppData\Local\Programs\Python\Python310\python.exe D:/PYTHONWITHSELENIUMTESTING/PythonPrograms/ChromeTrigger.py 
Traceback (most recent call last):
  File "D:\PYTHONWITHSELENIUMTESTING\PythonPrograms\ChromeTrigger.py", line 11, in <module>
    driver = webdriver.Chrome(executable_path = service_obj)
AttributeError: module 'selenium.webdriver.chrome.webdriver' has no attribute 'Chrome'

Process finished with exit code 1

Error snapshot:

1

CodePudding user response:

change your chrome driver path like this

service_obj="D:/PYTHONWITHSELENIUMTESTING/Chromedriver/chromedriver.exe"

CodePudding user response:

You need to pass the same Service() object which you have created within Chrome() as follows:

service_obj=Service("D:\\PYTHONWITHSELENIUMTESTING\\Chromedriver\\chromedriver.exe")
driver = webdriver.Chrome(service=service_obj)
driver.get("https://www.youtube.com/")
  • Related