1.下載並安裝python,一般安裝linux系統,自帶有python,則python不用安裝。要下載可以在官網上下載;
或者使用下面命令安裝:
sudo apt-get install python-virtualenv
2.下載安裝python管理工具包:pip;
sudo apt-get install python-pip
3.安裝setuptools:
sudo apt-get install python-setuptools
4.下載安裝selenium:注意,使用root權限安裝,否則會出現安裝不上。
參考selenium官方使用手冊:http://selenium-python.readthedocs.org/en/latest/getting-started.html
pip install -U selenium
5. 關於Webdriver
安裝的selenium2默認支持的webdriver是Firefox瀏覽器,如果要使用chrome或IE等其他瀏覽器則需要下載相關的驅動,如chromedriver或IEdriver;
下面使用默認的Firefox進行測試:
from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.send_keys("pycon") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source driver.close()
最后會打開python的官方網址。
chrome瀏覽器的配置可參考:
http://blog.likewise.org/2015/01/setting-up-chromedriver-and-the-selenium-webdriver-python-bindings-on-ubuntu-14-dot-04/