首页 > 解决方案 > 无法运行测试脚本。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

标签: pythonseleniumpycharmchrome-web-driver

解决方案


推荐阅读