Python & Selenium & Pycharm environment setup

Recently, I am studying python+selenium for automated testing. Then the python development tool used is Pycharm. Then, today I will tell you how to build a complete set of automated testing environment.

install python

First, install python. python can be downloaded from the official website. Installation can refer to the link: http://blog.csdn.net/florachy/article/details/72769813

I have python 3.6.0 installed:


Configure environment variables

Generally, if the automatic creation of environment variables is checked during the installation process, we do not need additional manual configuration.

Configure environment variables, add python's C:\Program Files\Python36 directory to the system environment variable path, and you can use python directly under DOS commands.

If you add C:\Program Files\Python36\Scripts to the path, you can use pip directly in DOS commands. Otherwise, you have to go to this directory every time you install selenium and use pip.



install selenium

Installation: pip install selenium ==XXXX without the version number, the latest version will be installed
Uninstall: pip uninstall selenium
Check the version number: pip show selenium

When I installed selenium before, I always reported an error, but after I upgraded the win10 home version to the professional version, there was no error. If you encounter this, you can consider whether this is the cause.



Browser Driver Placement

To start the browser through a script, you need to place the browser driver in the python installation directory, as shown in the following figure:


Install Pycharm

Reference link: http://blog.csdn.net/florachy/article/details/76647954


Pycharm configuration

When we enter "from selenium import webdriver" in Pycharm, we will find the following prompts:



We need to configure python's compiler. Select the directory where the correct python.exe is located. Click "Apply-OK".


Then you can write python scripts normally!


Script example



When running the above script, the following error is reported:



I found out later that it was because I changed the name of geckodriver.exe. So the browser driver should be properly prevented in the python directory like this:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325410772&siteId=291194637
Recommended