Selenium Python in console
原文链接 http://www.k8s.tips/blogs/2013/01/03/Selenium_Python_in_console/
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。
Selenium a powerful suite of tools for web testing, but it’s dependent on browser (Firefox, IE, Chrome); and those browser need a displayer. As a console/command geek, it’s intolerable. After several days investigation, I’d like to introduce PyVirtualDisplay to run Selenium in a console with Python.
Selenium introduction
Selenium automates browsers. That’s it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.
Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
Selenium in console
Selenium a powerful suite of tools for web testing, but it’s dependent on browser (Firefox, IE, Chrome); and those browser need a displayer. As a console/command geek, it’s intolerable. After several days investigation, I’d like to introduce PyVirtualDisplay to run Selenium in a console with Python.
Install in Ubuntu
sudo apt-get install python-pip
sudo apt-get install xvfb
sudo apt-get install xserver-xephyr
sudo apt-get install tightvncserver
sudo pip install pyvirtualdisplay
sudo pip install selenium
Start selenium in console
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
driver= webdriver.Firefox()
actions = webdriver.ActionChains(driver)
driver.get("http://www.reeline.com/arch/index.html")
print driver.title
driver.close()
display.stop()
Other purposes
- Increase the PV of a web site
- Cheat in adsense & Baidu union