+selenium Environment Building under Windows Python environment

Source: Internet
Author: User

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 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-8  from  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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.