Forums

Selenium + PyVirtualDisplay

Followed the instructions here: https://help.pythonanywhere.com/pages/selenium/ to set it up. Was able to install pyvirtualdisplay and Selenium (2.53.6). Not using a virtualenv

However, I'm still getting an error running the following code:

from pyvirtualdisplay import Display
from selenium import webdriver
with Display():
    browser = webdriver.Firefox()
    try:
        browser.get('http://www.google.com')
        print(browser.title)
    finally:
        browser.quit()

Error message: FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'. I thought geckodriver wasn't needed?

If it's trying to use Geckodriver, I don't think it can be Selenium 2.53.6 -- somehow, a more recent version must be being used. Which version of Python are you using? What do you get if you run

pip3.6 show selenium

...replacing the "3.6" with the version of Python you're using?

Ah interesting. Here's what I get:

Name: selenium Version: 3.0.2 Summary: Python bindings for Selenium Home-page: https://github.com/SeleniumHQ/selenium/ Author: UNKNOWN Author-email: UNKNOWN License: UNKNOWN Location: /usr/local/lib/python3.6/dist-packages Requires:

Can I downgrade the package or do I have to reinstall?

Yes, you can downgrade it -- just run

pip3.6 install --user selenium==2.53.6

awesome thanks!

No problem, glad to help!