It seems like I am missing some configuration in order to run tests properly. Steps I followed: -In a new folder I create a "main.py" file. -Created a new virtual environment through terminal using "python3 -m venv .venv" command -Clicked "Yes" on the "We noticed a new environment has been created. Do you want to use it" message on my IDE -Killed the terminal and executed the following code by running "python3 main.py" command
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome( ./chromedriver )
driver.get("https://www.python.org")
print(driver.title)
我收到以下错误信息:
% python main.py
Traceback (most recent call last):
File "/Users/xxxx/mechanized/.venv/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/xxxx/mechanized/.venv/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 87, in driver_location
browser = options.capabilities["browserName"]
^^^^^^^^^^^^^^^^^^^^
AttributeError: str object has no attribute capabilities
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xxxx/mechanized/main.py", line 4, in <module>
driver = webdriver.Chrome( ./chromedriver )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xxxx/mechanized/.venv/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/Users/xxxx/mechanized/.venv/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/xxxx/mechanized/.venv/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: str object has no attribute capabilities