问题
在windows11系统上安装的python 环境,通过pytest执行用例提示
NoSuchDriverException,本地已配置chrome,版本啥的都能对上,请教下有遇到过并知道怎么解决吗
报错信息
D:\PythonProject\venv\Scripts\python.exe "D:\install_software\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py" --target test_demo.py::test_demo
Testing started at 22:15 ...
D:\install_software\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import iter_entry_points
D:\install_software\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py:28: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Launching pytest with arguments test_demo.py::test_demo --no-header --no-summary -q in D:\PythonProject
if version.LooseVersion(pytest.__version__) >= version.LooseVersion("6.0"):
============================= test session starts =============================
collecting ... collected 1 item
test_demo.py::test_demo FAILED [100%]
test_demo.py:5 (test_demo)
self = <selenium.webdriver.common.driver_finder.DriverFinder object at 0x000001BA31AFE190>
def _binary_paths(self) -> dict:
if self._paths["driver_path"]:
return self._paths
browser = self._options.capabilities["browserName"]
try:
path = self._service.path
if path:
logger.debug(
"Skipping Selenium Manager; path to %s driver specified in Service class: %s", browser, path
)
if not Path(path).is_file():
raise ValueError(f"The path is not a valid file: {path}")
self._paths["driver_path"] = path
else:
output = SeleniumManager().binary_paths(self._to_args())
if Path(output["driver_path"]).is_file():
self._paths["driver_path"] = output["driver_path"]
else:
raise ValueError(f'The driver path is not a valid file: {output["driver_path"]}')
if Path(output["browser_path"]).is_file():
self._paths["browser_path"] = output["browser_path"]
else:
> raise ValueError(f'The browser path is not a valid file: {output["browser_path"]}')
E ValueError: The browser path is not a valid file:
venv\lib\site-packages\selenium\webdriver\common\driver_finder.py:75: ValueError
The above exception was the direct cause of the following exception:
def test_demo():
> driver = webdriver.Chrome()
test_demo.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py:45: in __init__
super().__init__(
venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py:50: in __init__
if finder.get_browser_path():
venv\lib\site-packages\selenium\webdriver\common\driver_finder.py:47: in get_browser_path
return self._binary_paths()["browser_path"]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.common.driver_finder.DriverFinder object at 0x000001BA31AFE190>
def _binary_paths(self) -> dict:
if self._paths["driver_path"]:
return self._paths
browser = self._options.capabilities["browserName"]
try:
path = self._service.path
if path:
logger.debug(
"Skipping Selenium Manager; path to %s driver specified in Service class: %s", browser, path
)
if not Path(path).is_file():
raise ValueError(f"The path is not a valid file: {path}")
self._paths["driver_path"] = path
else:
output = SeleniumManager().binary_paths(self._to_args())
if Path(output["driver_path"]).is_file():
self._paths["driver_path"] = output["driver_path"]
else:
raise ValueError(f'The driver path is not a valid file: {output["driver_path"]}')
if Path(output["browser_path"]).is_file():
self._paths["browser_path"] = output["browser_path"]
else:
raise ValueError(f'The browser path is not a valid file: {output["browser_path"]}')
except Exception as err:
msg = f"Unable to obtain driver for {browser}"
> raise NoSuchDriverException(msg) from err
E selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
venv\lib\site-packages\selenium\webdriver\common\driver_finder.py:78: NoSuchDriverException
============================= 1 failed in 11.48s ==============================
Process finished with exit code 1
###本地命令验证是能找到driver的
C:\Users\seren>chromedriver --version
ChromeDriver 126.0.6478.126 (d36ace6122e0a59570e258d82441395206d60e1c-refs/branch-heads/6478@{#1591})