Skip to content

Instantly share code, notes, and snippets.

@jobliz
Created June 3, 2018 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jobliz/542445975352fe9c734b86bdc083c7e5 to your computer and use it in GitHub Desktop.
Save jobliz/542445975352fe9c734b86bdc083c7e5 to your computer and use it in GitHub Desktop.
Selenium basic test using headless firefox and arbitrary binary and driver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
# https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu
# https://stackoverflow.com/questions/25713824/setting-path-to-firefox-binary-on-windows-with-selenium-webdriver
# http://selenium-python.readthedocs.io/getting-started.html
binary = FirefoxBinary(PATH_TO_BINARY)
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(
firefox_binary=binary,
executable_path=r'PATH_TO_DRIVER',
firefox_options=options)
print("Headless Firefox Initialized")
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment