How to properly setup Windows7 to use Selenium with Firefox [TDD with Python]?

前端 未结 2 846
野的像风
野的像风 2021-01-16 02:49

I\'m getting my system (Windows 7 Pro 64 bit, Python 3.5 through Anaconda) setup to use Firefox through selenium to follow the book Test Driven Development with Python.<

相关标签:
2条回答
  • 2021-01-16 03:05
    1. Selenium used to reference a driver called wires.exe (github-geckodriver issue 90). As of Selenium3 that driver has been replaced with geckodriver.exe. Install/upgrade to the latest selenium by running pip install "selenium>=3.0.0"
    2. Download the latest geckodriver for your platform: as of this writing that would be geckodriver-v0.11.1-win64.zip for 64 bit or geckodriver-v0.11.1-win32.zip for 32 bit. In your case the version %1 error has to do with an incorrect geckodriver version. Extract this zip to C:\Users\YourUserName\Downloads\selenium_driver
    3. Install the Firefox Extended Support Release setting the custom installation path to C:\Program Files\Mozilla FirefoxESR if on 64 bit or C:\Program Files (x86)\Mozilla FirefoxESR if on 32 bit.

    If setting the Windows PATH to C:\Users\YourUserName\Downloads\selenium_driver doesn't seem to work (so that selenium can find geckdriver.exe) you can instead specify its directory in your Python script as follows:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    gecko = r'C:\Users\YourUserName\Downloads\selenium_driver\geckodriver.exe'
    ffox_binary = FirefoxBinary(r'C:\Program Files\Mozilla FirefoxESR\firefox.exe') #for 64 bit installation
    #ffox_binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla FirefoxESR\firefox.exe') #for 32 bit installation
    browser = webdriver.Firefox(firefox_binary=ffox_binary, executable_path=gecko)  
    browser.get('http://localhost:8000')
    
    0 讨论(0)
  • 2021-01-16 03:11

    Make sure you have downloaded GeckoDriver for win-64 bit as you have 64-bit machine. Now copy paste downloaded GeckoDriver executable inside 'Script' folder(this folder is present inside the root folder where python is installed in your system). Now set the path of python root folder and 'Script' folder in Environment variable

    C:\..Python; //path of python root folder 
    C:\..Python\Scripts; //path of python 'Script' folder
    

    Don't forget to restart your system for the changes to take effect & try this sample code

    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.get("http://google.com")
    
    0 讨论(0)
提交回复
热议问题