Python Selenium 帮助错误 - 回溯(最近一次调用):

时间:2020-12-31 20:04:42

标签: python selenium

我好多年没有编程了。我正在尝试学习自动化工作任务。在遇到一些问题后,我能够成功为 Python 安装 selenium。

这是我试图测试以确保安装成功的简单程序。

注意 - 我在安装 selenium 时遇到问题,所以我必须设置路径和其他一些东西。所以我认为其中一些变化可能影响了这个 Python 程序的运行。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

当我在命令提示符下运行程序时,这就是我得到的。

>py main.py
Traceback (most recent call last):
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jonab\Documents\Python Projects\Amazon SC Review Automation\main.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "C:\Users\jonab\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

我确实参考了这篇文章并运行了他们的代码,但遇到了不同的错误。 Python Selenium Traceback (most recent call last):

0 个答案:

没有答案
相关问题