Created
June 3, 2018 17:29
-
-
Save jobliz/542445975352fe9c734b86bdc083c7e5 to your computer and use it in GitHub Desktop.
Selenium basic test using headless firefox and arbitrary binary and driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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