Selenium 在 Python 中不起作用

Selenium not working in Python

我对 Selenium 有疑问! 我尝试了 3.6 和 2.7,但没有区别! 我正在使用 win7(64 位)

让我们从一个简单的代码开始:

binary = FirefoxBinary(r"C:\Program Files\Mozilla Firefox\firefox.exe")
fp = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp)

所以,我得到了这些错误:

C:\Python27\python.exe E:/Python/MathBattle_Solver/test.py

Traceback (most recent call last): File "E:/Python/MathBattle_Solver/test.py", line 13, in download("https://www.google.com")

File "E:/Python/MathBattle_Solver/test.py", line 9, in download browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=r'C:\Windows\System32\geckodriver.exe')

File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in init self.service.start()

File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message: 'geckodriver.exe' executable needs to be in PATH.

我下载了"geckodriver.exe",把它放到system32文件夹里,从环境变量里加入PATH系统变量,但是没有任何反应!还是一样的错误!

有什么想法吗?

它适用于 52.0.2(64 位)和 Geckodriver 0.15.0-win64(来自 https://github.com/mozilla/geckodriver/releases)。

将geckodriver.exe放入脚本文件夹,然后用

调用webdriver.Firefox
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp, executable_path='geckodriver.exe')

Selenium 需要驱动程序才能与所选浏览器交互。例如 Firefox,需要 geckodriver,需要先安装 geckodriver,下面的例子才能 运行。确保它在你的路径中,e。例如,将其放在 /usr/bin 或 /usr/local/bin.

未能遵守此步骤会给您一个错误selenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要在 PATH

将geckodriver.exe放入脚本文件夹,然后用

调用webdriver.Firefox