Transferred from: http://www.myext.cn/webkf/a_11878.html
1. Download the necessary tools and installation packages
1.1 "python development Environment"
Download and install the Python 2.7.x version
:https://www.python.org/downloads/
1.2 "Python's installation package management tool"Pip
Pip is a Python software package installation and management tool, with this tool, we only need a command to be able to easily Python any class library.
: Https://pypi.python.org/pypi/pip
(drag directly to the bottom of the page to download the tar.gz Package | MD5 is a file check)
Note: or download the following link file (installation requires networking)
https://bootstrap.pypa.io/get-pip.py
1.3. "Python's Basic Package tool" Setuptools
Setuptools is a Python-based package tool that can help us easily download, build, install, upgrade, and uninstall Python packages.
: Http://pypi.python.org/pypi/setuptools
(drag directly to the bottom of the page to download tar.gz and zip packages can be | MD5 is a file check)
Note: Or if you are a Win7 system you can download the following link file directly (installation requires networking)
https://bootstrap.pypa.io/ez_setup.py
1.4. "Python for Selenium installation package"
The main is to let the integration of Selenium Webdriver API.
: Https://pypi.python.org/pypi/selenium
2. Environment installation (Windows)
2.1. Install the Python environment:
Double-click the downloaded Python for window installation package Python-2.7.11.msi, next-next .... , the default installation directory is C:\Python27, and the Python environment variable is configured after the installation is complete. such as
Add the Python installation path to the system environment path:
(This step is critical, not setting causes other toolkits to fail the installation, because all toolkits are done using Python commands, to reduce the hassle of setting environment variables as soon as the Python installation is complete)
2.2. Install PIP
Mode one (tested to be possible ~ ~):
Unzip the downloaded installation package, cmd window into the extract directory of PIP use the following command to install
d:\downloads\pip-8.1.2> python setup.py Install
Then go to the C:\Python27\Scripts directory and execute the following command
C:\Python27\Scripts > Easy_install pip
method Two: install using the downloaded get-pip.py
D:\downloads>python get-pip.py
2.3. Installing Setuptools
Mode one (tested to be possible ~ ~):
Unzip the downloaded installation package, cmd window into the setuptools extract directory use the following command to install
D:\downloads\setuptools-22.0.0>python setup.py Install
Way two:
WIN7 system into the downloaded ez_setup.py directory run the following command to download the installation automatically
D:\downloads\setuptools-22.0.0>python ez_setup.py
Way three:
Go to the installation directory where the PIP is installed execute the following command to install online
C:\Python27\Scripts >pip install-u Setuptools
2.4. Installing Selenium
Mode one (tested to be possible ~ ~):
Go to the directory where Python is installed execute the following command to install online
C:\Python27\Scripts >pip install-u Selenium
Way two:
Unzip the downloaded selenium package and place the entire directory in the C:\Python27\Lib\site-packages directory (python installation path) .
================================ installation is complete under Windows system Selenium Webdriver + python environment ========= =======================
3. Test the Applet
Create a Notepad file named openbaidu.py (name can be customized)
Enter the following in the document and save:
fromSeleniumImportWebdriverImportTimedriver=Webdriver. Firefox () Driver.get ("http://www.baidu.com") driver.find_element_by_id ("kw"). Clear () driver.find_element_by_id ("kw"). Send_keys ("Selenium") driver.find_element_by_id ("kw"). Click ()PrintDriver.titletime.sleep (4) Driver.quit ()
After running the script will automatically open the Firefox Browser, and enter the Baidu homepage, automatically enter "Selenium" to search, wait 5 seconds, automatically close the page.
"Go" Selenium webdriver + Python Environment