Skip to content

Instantly share code, notes, and snippets.

@swang373
Created October 24, 2019 16:03
Show Gist options
  • Save swang373/53a8f54c78b33acc822c20af5e6cd349 to your computer and use it in GitHub Desktop.
Save swang373/53a8f54c78b33acc822c20af5e6cd349 to your computer and use it in GitHub Desktop.
Running a headless Firefox browser using Selenium webdriver
from selenium import webdriver
def main():
# Setup options to run Firefox in headless mode.
firefox_options = webdriver.FirefoxOptions()
firefox_options.headless = True
# Open a Firefox browser and check the Python official site.
driver = webdriver.Firefox(options=firefox_options)
# If there's lots of dynamic content, have the browser wait a few seconds.
driver.implicitly_wait(5)
driver.get('https://www.python.org')
assert "Python" in driver.title
driver.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment