简体   繁体   English

无法运行webdriver.selenium webdriver的Firefox

[英]cannot run webdriver.Firefox from selenium webdriver

I am having trouble using Selenium 我在使用硒时遇到问题

I am using Python 3.6, on a Windows 7 machine at my workplace. 我在工作场所的Windows 7计算机上使用Python 3.6。 Firefox is 61.0.1 (64-bit) Python is loaded in C:\\Program Files (x86)\\Python36-32 Firefox是61.0.1(64位),Python加载在C:\\Program Files (x86)\\Python36-32

My work is in H:\\PythonPrograms 我的工作在H:\\PythonPrograms

I have successfully installed selenium: C:\\Windows\\System32> pip install selenium Requirement already satisfied: selenium in c:\\program files (x86)\\python36-32\\lib\\site-packages (3.13.0) 我已经成功安装了硒:C:\\ Windows \\ System32> pip install selenium Requirement already satisfied: selenium in c:\\program files (x86)\\python36-32\\lib\\site-packages (3.13.0)

Per other advice found here, I downloaded geckodriver.exe and placed it both into C:\\Program Files (x86)\\Python36-32 and H:\\PythonPrograms . 根据此处找到的其他建议,我下载了geckodriver.exe并将其都放入C:\\Program Files (x86)\\Python36-32H:\\PythonPrograms

My path includes: C:\\Program Files (x86)\\Python36-32\\Scripts\\;C:\\Program Files (x86)\\Python36-32\\;H:\\PythonPrograms 我的路径包括: C:\\Program Files (x86)\\Python36-32\\Scripts\\;C:\\Program Files (x86)\\Python36-32\\;H:\\PythonPrograms

I am following the steps on "Automate the Boring Stuff with Python" (Al Sweigart) p. 我正在按照“使用Python自动完成无聊的事情”(Al Sweigart)p中的步骤进行操作。 257 257

>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    browser = webdriver.Firefox()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
    log_path=log_path)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
    log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'


>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
    log_path=log_path)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
    log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>> 

(IT's not the permissaion on geckodriver.log. This even happens when I delete that file and try again. Also I checked permissions: ) (这不是geckodriver.log上的权限。当我删除该文件并重试时,甚至会发生这种情况。我还检查了权限:)

When I run Python as administrator from a new Python session: 在新的Python会话中以管理员身份运行Python时:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
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 "<pyshell#3>", line 1, in <module>
    browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
    self.service.start()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'PythonPrograms' executable needs to be in PATH.

I don't understand what is happening between me running Python normally vs running as administrator. 我不了解正常运行Python与以管理员身份运行之间发生了什么。 Whichever, neither way gives me expected output. 无论哪种方式,都无法给我预期的输出。


added new run example by changing the executable_path to include the program name and remove the "r" qualifier. 通过更改可执行文件路径以包括程序名称并删除“ r”限定符来添加新的运行示例。 Here are the new results: 以下是新结果:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    keep_alive=True)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

>>> 

而不是使用正则表达式,请尝试使用exe文件名提供确切的路径

browser = webdriver.Firefox(executable_path='H:\PythonPrograms\yourexenamehere.exe')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM