2016-10-15 57 views
4

我最近下载的硒,并试图运行此脚本:蟒蛇的webdriver eror

from selenium import webdriver 
driver = webdriver.Firefox() 

,但我得到这个错误:

Traceback (most recent call last): 
    File "<pyshell#3>", line 1, in <module> 
    driver = webdriver.Firefox() 
    File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 145, in __init__ 
    keep_alive=True) 
    File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 92, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 179, in start_session 
    response = self.execute(Command.NEW_SESSION, capabilities) 
    File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 192, in check_response 
    raise exception_class(message, screen, stacktrace) 
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'firefox_binary' capability provided, and no binary flag set on the command line 

哦,顺便说一下这个打开我面前geckodriver.exe其写错误

+0

并且您是否安装了Firefox?你有没有试过告诉Selenium它在哪?如果你使用的是便携式应用,他们可能会把事情放在非传统的地方,这会破坏东西。 – jonrsharpe

+0

感谢评论,我安装了fire fox,我怎么告诉硒在哪里?我使用便携式应用程序,你认为我应该删除它,并没有它下载python? – omersk

+0

你正在使用哪个版本的Firefox? – Piyush

回答

7

我通过手动设置二进制位置解决了这个问题,如下面的答案:

https://stackoverflow.com/a/25715497

记得设置你的二进制文件到firefox二进制文件的实际位置在您的计算机上

如:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe') 
self.browser = webdriver.Firefox(firefox_binary=binary) 

(注:在文件路径中的第一次报价之前的“R”字符串会使python看到字符串为'raw'文本,因此您不需要像'\'那样转义字符 - 您可以将其放在路径中,因为它实际上是)