python - 无法运行测试脚本。PyCharm Selenium Python 测试
问题描述
我可以运行脚本进行自动测试。
这是脚本
from selenium import webdriver
PATH = "Z:\PyProjects\venv\Scripts\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://google.com/")
这是我在运行脚本后遇到的错误
Z:\PyProjects\venv\Scripts\python.exe Z:/PyProjects/test.py
Traceback (most recent call last):
File "Z:\PyProjects\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] unable to find the file
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Z:/PyProjects/test.py", line 3, in <module>
driver = webdriver.Chrome(PATH)
File "Z:\PyProjects\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "Z:\PyProjects\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
解决方案
推荐阅读
- prolog - 对 prolog 工作原理的误解
- python - 如何在 If 语句中退出/中断 Python 自动化脚本(不在循环内)
- swift - 如果 ForEach 循环嵌套,SwiftUI LazyHStack / LazyVStack 是否仍然有效?
- php - 如何使用 $request 在 symfony 中请求数据
- mysql - 将列的聚合与同一表的另一列进行比较
- algorithm - 如何使用约束解决分配问题?
- json - Tornadofx REST 客户端
- zsh - 如何知道安装了哪个ZSH配置框架?
- python - 我什么时候可以在 PCA 之前或之后将我的数据集拆分为训练和验证集?
- angular - 总是调用 flatMap 中的第二个 API