【发布时间】:2019-06-13 03:47:45
【问题描述】:
我正在尝试用 selenium 打开 Firefox,我试过了
from selenium import webdriver
driver=webdriver.Firefox()
但我收到以下错误:
selenium.common.exceptions.WebDriverException: Message: 'firefox' executable needs to be in PATH.
Selenium using Python - Geckodriver executable needs to be in PATH
我试过了
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/usr/bin/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
也试过
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps['marionette'] = True
caps['binary'] = '/usr/bin/firefox'
d = webdriver.Firefox(capabilities=caps)
`但还是不行。
但是,当我尝试使用上面的代码替换最后一行时
d=webdriver.Firefox(capabilities=caps,executable_path='/usr/bin/firefox') 并让我的 Firefox 从后台关闭,它会打开 Firefox,但我不能简单地 d.get("https://www.google.com") 它卡在 Linux 主页上并且什么也没有打开。
在终端输入whereis firefox 后,我得到/usr/bin/firefox,如果重要的话,我使用python 2.7
注意:我希望这不是上述链接的重复,因为我尝试了答案,但没有解决。
我从github安装了geckodriver,试了browser=webdriver.Firefox(executable_path="geckodriver"),我把驱动放在同一个目录下。
【问题讨论】:
标签: python python-2.7 selenium firefox geckodriver