1. Tools Download:
The Python tool consists of three: Python, Setuptools, Pip
²python:http://python.org/getit/python development environment;
²setuptools:http://pypi.python.org/pypi/setuptools/python's basic Package tool;
²pip:http://pypi.python.org/pypi/pip Python's installation package management tool;
2. Installation of Windows environment
First step: Install python2.7 with default path installation
Step Two: Install Setuptools, unzip the file, locate the ez_install.py file, go to the Windows command line, execute the ez_install.py file. such as: C:\setuptools-1.3>python ez_install.py;
Add Python environment variable: variable name: PATH variable value:; c:\Python27
Step Three: Install Pip
C:\pip-1.4.1\python setup.py Install
C:\Python27\Scripts >easy_install Pip
Fourth Step: Install Selenium
If the computer is connected, you can enter it directly under C:\Python27\Scripts:
Pip Install-u Selenium, if not in: Http://pypi.python.org/pypi/selenium download.
3. Python shortcut keys
tab: syntax completion; ALT+P: Fallback to the previously entered code statement; Alt+n: Move to the next code statement.
Import Selenium related modules: from selenium import Webdriver
4. First Automation script
#coding = Utf-8
From selenium import Webdriver #要用到webdriver函数, first import the package
Browser = Webdriver. Firefox () #用火狐浏览器
Browser.get ("http://www.baidu.com") #用浏览器打开百度首页
browser.find_element_by_id ("kw"). Send_keys ("Selenium") #通过ID定位id为 "kw" element with a value of selenium
browser.find_element_by_id ("su"). Click () #通过ID定位id为su的元素, and tap action
Browser.quit () #退出浏览器
Selenium python (i) Development environment construction