First, install Python
1. Download the Python package, previous version of the latest version: https://www.python.org/downloads/windows/
2. Installation
You can choose a default installation or a custom installation, and the custom installation specifies the path to be installed, always next, until the installation is successful.
3. Test if Python is installed successfully:
Under any path, go to cmd, enter Python, and the Python version number shown below is installed successfully.
Second, build selenium framework
1. Download selenium:https://pypi.org/project/selenium/
The downloaded selenium is a. WHL suffix file that requires the installation of the wheel tool, which is the following command.
Pip Install Wheel
Then perform the installation selenium
Pip Install absolute path \SELENIUM-3.12.0-PY2.PY3-NONE-ANY.WHL
2. Verify that the selenium is installed successfully:
Open Python's idle tool and enter
From selenium import Webdriver
Results without error such as installation success:
Third, write a simple automation script
Windows users, find the Python directory in the Start menu, open the idle (Python GUI) program, and start with an interactive mode. You can enter: from selenium import Webdriver
The above command is to import selenium related packages, if no error after carriage return indicates that our selenium installation is successful.
CTRL + N or file->new file opens a new window and enters the following code:
# coding = Utf-8from Selenium Import webdriverbrowser = Webdriver. Chrome () browser.get ("http://www.baidu.com") browser.find_element_by_id ("kw"). Send_keys ("Selenium") browser.find_ element_by_id ("su"). Click () browser.quit ()
After the input is complete, save.
Need to install Chrome browser driver before running: https://github.com/DaemonFG/IntrotoPython-Think-Tank/blob/master/P2/ChromeDriver_Download.md
Choose any version, the latest version is recommended, after the download is completed in the Python installation directory.
Return to Idle press F5 to run the code successfully.
Iv. Installation of browser drivers
Change the browser in the above code to Firefox (), run, because Firefox browser does not install browser drivers, resulting in the operation of the report as the following error:
Install Mozilla Firefox drive: https://github.com/mozilla/geckodriver/releases
Download the corresponding version of the drive:
After decompression, copy the driver files to the Python installation directory and rerun the code to succeed.
+selenium Environment Building under Windows Python environment