Using Selenium with Python & Firefox (geckodriver) CentOS
I'm going to use Python 2.7.5 installed by default.
Install Selenium:
sudo yum install python-pip -y
sudo pip install --upgrade pip
sudo pip install selenium
Install geckodriver:
tar xzvf geckodriver-needed-version
mv geckodriver /usr/local/bin
Install Firefox Nightly:
As geckodriver Supported Firefoxen states:geckodriver is not yet feature complete. This means that it does not yet offer full conformance with the WebDriver standard or complete compatibility with Selenium .... Some features will only be available in the most recent Firefox versions, and we strongly advise using the latest Firefox Nightly with geckodriver....Go to https://www.mozilla.org/en-US/firefox/58.0a1/releasenotes/ and download Firefox Nightly. It doesn't need installation or compiling, just "tar xjvf" tar.bz2 file in desired directory (/home , /opt etc.) the same directory will be used in the Python code in the below section.
Python code to test WebDriver:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver as wbdr
binary = wbdr.
firefox.firefox_binary.
FirefoxBinary('/opt/firefox/firefox')
browser = webdriver.Firefox(firefox_binary=binary)
browser.get("http://google.com")
browser.quit()
Newer versions of Selenium will not be supporting FirefoxBinary (some versions will give you Deprecation warning). Use below instead of FirefoxBinary:
opts = wbdr.firefox.options.Options()
opts.binary_location = '/home/admino/firefox/firefox'
srvc = wbdr.firefox.service.Service('/usr/local/bin/geckodriver')
browser = wbdr.Firefox(service=srvc, options=opts)
No comments:
Post a Comment