I'm trying to create a selenium code in my computer but it is not working. The code is:
from selenium import webdriver
from pathlib import Path
chromedriver_path:str = Path(__file__).absolute().parent / 'chromedriver'
driver = webdriver.Chrome(chromedriver_path)
driver.get("www.google.com")
When I try to run it, it shows me the following error
Traceback (most recent call last):
File "/Users/macklee/anaconda3/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/macklee/anaconda3/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 87, in driver_location
browser = options.capabilities["browserName"]
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/macklee/Desktop/Computer science/Studies/Python/Paulla gomes project/navagation.py", line 5, in
driver = webdriver.Chrome(chromedriver_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/macklee/anaconda3/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/Users/macklee/anaconda3/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 49, in __init__
self.service.path = DriverFinder.get_path(self.service, options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/macklee/anaconda3/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 40, in get_path
msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'capabilities'
path = Path(__file__).absolute().parent / "chromedriver.exe"or try reinstalling the selenium package.