launch selenium from python on ubuntu

后端 未结 2 1237
情话喂你
情话喂你 2020-12-18 15:57

I have the following script

from selenium import webdriver

browser = webdriver.Firefox()
browser.get(\'http://localhost:8000\')

assert \'Django\' in browse         


        
相关标签:
2条回答
  • 2020-12-18 16:27

    The last version of Firefox is not working properly with selenium. Try with 46 or 45.

    You can download here: ftp.mozilla.org/pub/firefox/releases

    or sudo apt-get install firefox=45.0.2+build1-0ubuntu1

    You can also do this graphically as shown here http://www.howtogeek.com/117929/how-to-downgrade-packages-on-ubuntu/

    0 讨论(0)
  • 2020-12-18 16:29

    I struggled with this problem as well, and I was unhappy with having to use older versions of Firefox. Here's my solution that uses the latest version of Firefox. It however involves several steps

    Step 1. Download v0.9.0 Marionette, the next generation of FirefoxDriver, from this location: https://github.com/mozilla/geckodriver/releases/download/v0.9.0/geckodriver-v0.9.0-linux64.tar.gz

    Step 2. Extract the file to a desired folder, and rename it to "wires". In my case I created a folder named "add_to_system_path" under Documents. So the file is in Documents/add_to_system_path/wires (also make sure that the wires file is executable under its properties)

    Step 3. Create a file named ".pam_environment" under your home folder, and then adding this line on it and save

    PATH DEFAULT=${PATH}:/absolute/path/to/the/folder/where/wires/is/saved

    What this does is it tells ubuntu to add the enumerated dir in .pam_environment to your system path

    Step 4. Save the file, log out of your user session, and log back in. This is necessary to do so that the files in the newly added system path is recognized by ubuntu

    Step 5. Use the code below to instantiate the browser instance:

    `
    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    capabilities = DesiredCapabilities.FIREFOX
    capabilities["marionette"] = True
    browser = webdriver.Firefox(capabilities=capabilities)
    browser.get('http://your-target-url')`
    

    Firefox should now be able to instantiate as usual.

    0 讨论(0)
提交回复
热议问题