Skip to content

Instantly share code, notes, and snippets.

@yunlzheng
Created October 19, 2014 14:03
Show Gist options
  • Select an option

  • Save yunlzheng/4f251a78f11a68ecd2e0 to your computer and use it in GitHub Desktop.

Select an option

Save yunlzheng/4f251a78f11a68ecd2e0 to your computer and use it in GitHub Desktop.
vagrant or docker run functional with xvfn
# coding = utf-8
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.baidu.com')
browser.save_screenshot('baidu_home.png')
elem = browser.find_element_by_id('kw') # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)
browser.save_screenshot('search_result.png')
browser.quit()
display.stop()
sudo apt-get install Xvfb
pip install PyVirtualDisplay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment