selenium.common.exceptions.WebDriverException:消息:"Mozilla Firefox"可执行文件在使用GeckoDriver时可能具有错误的权限 [英] selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions while using GeckoDriver
问题描述
我在尝试使用硒来完成浏览器操作时遇到了一些麻烦. 我是这种类型的超级入门者,但我仍然进行搜索,发现的最相关的响应是我需要以管理员身份运行该应用程序,但它没有任何改变.这是我的代码和错误消息.非常感谢.
I've had some trouble trying to get selenium to do stuff with browsers. I'm a super-beginner at this type of stuff, but I still searched, and the most pertinent response I found was that I needed to run the Application as administrator, but it didn't change anything. Here's my code and the error message. Thanks alot.
import time
from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")
我的错误消息:
Traceback (most recent call last):
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Axel\Desktop\PYTHON\code.py", line 3, in <module>
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions.
我很确定这两个错误只是一个,而且我已经经历了很多线程,但是我从来没有正确地理解过事情.我想知道它是否与geckdriver有关(我没有,也不知道如何安装.) 非常感谢!
I'm pretty sure these two errors are just one, and I've gone through a whole bunch of threads, but i never properly understand things. I wondered if it had something to do with geckdriver (which i havem't and don't know how to install.) Thanks alot!
推荐答案
此错误消息...
selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions.
...表示由于权限错误而无法访问 Mozilla Firefox 可执行文件.
...implies that the Mozilla Firefox executable was unaccessable due to wrong permissions.
在使用 Selenium v3.x , GeckoDriver 和 Firefox 时,您必须考虑以下事实:
While working with Selenium v3.x, GeckoDriver and Firefox you have to consider certain facts as follows:
- 您需要通过传递 GeckoDriver 二进制文件的绝对路径,而不是 Mozilla Firefox 二进制文件(即
firefox.exe
). 单引号(即''
)中的>自变量executable_path
,以及原始(r
)开关. - 您需要从此链接下载的最新版本
. a>,并确保 GeckoDriver 拥有必需的权限,以供非root用户用户访问. - 始终以非root 用户身份执行 TestCases / TestSuite .
-
您的有效代码块如下:
- Instead of Mozilla Firefox binary (i.e.
firefox.exe
) you need to pass the absolute path of the GeckoDriver binary through the argumentexecutable_path
within single quotes (i.e.''
) along with the raw (r
) switch. - You need to download the latest release of GeckoDriver from this link and ensure that GeckoDriver have required permissions to be accessed by non-root user.
- Always execute your TestCases/TestSuite as a non-root user.
Your effective code block will be as follows:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
这篇关于selenium.common.exceptions.WebDriverException:消息:"Mozilla Firefox"可执行文件在使用GeckoDriver时可能具有错误的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!