Created
October 19, 2014 14:03
-
-
Save yunlzheng/4f251a78f11a68ecd2e0 to your computer and use it in GitHub Desktop.
vagrant or docker run functional with xvfn
This file contains hidden or 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
| # 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() |
This file contains hidden or 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
| 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