I'm trying to get Python Selenium to work on my Windows Machine. I've upgraded to the latest versions of Firefox, Selenium, Geckodriver, but I still receive the below error:
Python Script
from selenium import webdriver
driver = webdriver.Firefox()
Error
Traceback (most recent call last):
File "run.py", line 17605, in <module>
File "<string>", line 21, in <module>
File "site-packages\selenium\webdriver\firefox\webdriver.py", line 77, in __init__
File "site-packages\selenium\webdriver\firefox\extension_connection.py", line 49, in __init__
File "site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
File "site-packages\selenium\webdriver\firefox\firefox_binary.py", line 103, in _wait_until_connectable
WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
I've also tried creating the firefox profile with the below code:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/vnd.ms-excel'))
profile.set_preference('general.warnOnAboutConfig', False)
gecko_path = "path_to_geckodriver\\geckodriver.exe"
path = "path_to_firefoxs\\Mozilla Firefox\\firefox.exe"
binary = FirefoxBinary(path)
driver = webdriver.Firefox(firefox_profile=profile,executable_path=gecko_path)
- Python 2.7
- Firefox 60
- Geckodriver-v0.20.1-win64.zip
- Selenium 3.12.0
Switch to the chrome driver. Firefox, gecko, and selenium are not working well together right now. Here is what finally worked for me.
I use a Jenkinsfile that loads the frame buffer to call selenium and the python script.
You could easily run this on your local machine. You may want to get a vagrant box going with linux.
Here is what launches the python script.
sh "(Xvfb :99 -screen 0 1366x768x16 &) && (python ./${PYTHON_SCRIPT_FILE})"
This is called from a docker file running this Docker image.
https://github.com/cloudbees/java-build-tools-dockerfile