Automated testing -selenium (python version)

A. Installation Python3

1. Go to the official Python website: https://www.python.org/downloads/  download and install the latest version of Python (recommended to install Python3).

  Below are a few differences Python online version of the official:

 

 

                     (1) .web-based installer need to be done by the network

                     (2) .executable installer is an executable file (* .exe) installed

                     (3) .embeddable zip file embedded version can be integrated into other applications.

The above three ways, if there is a network, select web-based;

 

2. Check whether the installation was successful: In the Windows command line (cmd), enter "python" command to test, if prompted Python is not an internal or external command, put the Python install directory to the Path following system environment variables.

  Note: Python3 default has been installed pip, pip is a Python package installation and management tools, we can use this tool to install selenium, the Windows command line (cmd) Input pip to see.

II. Installation selenium

     1. Method One: In the case of networking, the Windows command line (cmd) Input pip install -U selenium to automatically install selenium, after the installation is complete, enter pip show selenium selenium can view the current version, see the following figure.

 

 

 

2. Method Two: Download selenium package: https://pypi.python.org/pypi/selenium

After decompression, executed under the extracted directory C: \ selenium \ selenium3.3.1> python setup.py install to install

 

III. Driver driver install three major browsers

     1.chromedriver Download: http://chromedriver.storage.googleapis.com/index.html or  http://npm.taobao.org/mirrors/chromedriver/

    Then chromedriver.exe file into the \ Scripts in python installation directory

     2.Firefox drive geckodriver Download: https://github.com/mozilla/geckodriver/releases/

     3.IE drive IEdriver Download: http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

Note: After the download, unzip, will chromedriver.exe, geckodriver.exe, Iedriver.exe sent to the Python installation directory, such as D: \ python. Then add the Python install directory to the system environment variable Path below.

Then open the Python IDLE respectively enter the following code to launch different browsers

 

Start Google Chrome

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.com')

Start Firefox

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.baidu.com')

Start IE browser

from selenium import webdriver

browser = webdriver.Ie()
browser.get('http://www.baidu.com')

Guess you like

Origin www.cnblogs.com/siskin/p/11533140.html