首页 文章

Selenium在Python中不起作用

提问于
浏览
1

我有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(最近一次调用最后一次):文件“E:/Python/MathBattle_Solver/test.py”,第13行,下载(“https: //www.google.com“)文件”E:/Python/MathBattle_Solver/test.py“,第9行,下载浏览器= webdriver.Firefox(capabilities = firefox_capabilities,executable_path = r'C:\ Windows \ System32 \ geckodriver .exe')文件“C:\ Python27 \ lib \ site-packages \ selenium \ webdriver \ firefox \ webdriver.py”,第144行,在init self.service.start()文件“C:\ Python27 \ lib \ site -packages \ selenium \ webdriver \ common \ service.py“,第81行,在启动os.path.basename(self.path),self.start_error_message)selenium.common.exceptions.WebDriverException:消息:'geckodriver.exe'可执行文件需要在PATH中 .

我下载了“geckodriver.exe”,把它放到system32文件夹中并从环境变量添加到PATH系统变量中,但什么都没发生!还是一样的错误!

任何的想法?

1 回答

  • 2

    它适用于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')
    

相关问题