selenium and chrome driver installed in the python

selenium is a support for multiple languages, writing automated scripts for multiple browsers, multiple platforms, open source web automated testing software testers available python, java and other languages, making the browser can run entirely in accordance with your instructions, saving testers test of time with the mouse click.

But selenium webdriver to get up and running properly, we must first install the required packages, configuration-related environmental variables, I believe many people here eat deflated. All things are difficult, and everyone else, I also encountered a lot of "gotcha" In this step, two days time, online access to a lot of tutorials, and finally solve the problem of the script to run. Since I am using a script python to write, I'll write about the installation selenium and chromedriver under python I have come across (other browsers also have a corresponding webdriver installation package, I will take the chrome browser as an example of) problems and appropriate solutions.

A, python installation

1, download the installation package

python official website

To the official website to download the appropriate installation package (Mac and windows installation package is different)

Unix & Linux platform because I am not familiar with, so the Internet to find a tutorial: http: //www.runoob.com/python/python-install.html

python version is recommended to choose the version 3.X

 

 

 

 

After the download is complete, double-click the folder to its installation package, enter the installation wizard, follow the instructions to install python to your computer can be (note windows to distinguish between 32-bit and 64-bit, choose their own system consistent with the package)

2, verify successful installation

Press and hold the "win + r" cmd run, enter cmd in the python, and then press Enter, if you installed python version information appears, is the successful installation

 

 

 

 

Second, configure python environment variables (path)

1, by adding to the installation guide python

There hook python installation wizard option "add python 3.XX to PATH", after the check, python automatically during the installation path during installation of the filling to the PATH

2, the operator adds the command cmd environment variables

按住“win+ r”运行cmd,在cmd中输入“path=%path%;c:\python”(c:\python是python的安装路径)

 

 

 

 

 

3、通过设置添加环境变量

控制面板 - 系统和安全 - 系统

点击“高级系统设置”,点击“环境变量”,将python的安装路径复制到“系统变量”中

 

 

 

 

 

 

 
 

三、selenium的安装

使用python自带的pip安装

python3.X安装后默认就会有pip(pip.exe在python的scripts路径下),还是打开cmd,输入“pip install selenium”,看到进度条就表示正在安装,等到进度条变为百分之百则安装完成

四、浏览器的安装与配置环境变量(以chrome为例)

1、 下载安装包

https://www.google.com/chrome/,下载完成之后到相应文件夹双击安装包,根据安装引导一步一步地安装

2、将chrome的安装包(exe)复制到python的安装路径下

3、将chrome的安装路径配置到环境变量下(参考上面python的环境变量的配置)

五、chrome driver的安装

http://chromedriver.chromium.org/(此网站需要翻墙),在此网站下载chrome driver(同样也是区分了三个平台)

 

 

 

 

 

点击“chromedriver_win32.zip”下载,完成后将该压缩包解压到相应位置,点击“chromedriver.exe”进行安装

 

 

 

 

 

 
 

六、chromedriver的环境变量

方法一:复制chromedriver的安装路径,将其粘贴到系统变量中(参考python的环境变量配置)(没有试这个方法,不知道能不能用)

方法二:将chromedriver.exe文件,将其粘贴到python安装路径下,不用配置系统变量。(用的这个方法,亲测可行)

 

 

到此,selenium webdriver运行所需的所有条件都已配置好,你可以用Python写你的第一个脚本了(下面展示了几行很基本的代码,大概意思是打开chrome,输入“http://baidu.com”,然后在输入框中输入“selenium”,点击搜索,最后退出。这行代码可以帮助你检验selenium是否安装成功)

 

 

 

 
end




参考:简书:https://www.jianshu.com/p/dd848e40c7ad


Guess you like

Origin www.cnblogs.com/liuyanhang/p/11840482.html