Python安装Selenium3

时间:2023-03-10 01:50:25
Python安装Selenium3

概述

2016.10.13,Selenium3.0正式发布,官方说明如下:

The major change in Selenium 3.0 is we're removing the original Selenium Core implementation and replacing it with one backed by WebDriver. This will affect all users of the Selenium RC APIs. For more information, please see the previous post .……>>more

安装

首先,执行pip install selenium,如果你是2016年10月后首次用这个,你会惊奇地发现,自动安装的是Selenium3.0版本。

Python安装Selenium3

测试安装

接下来,我们在Python解释器中测试一下能不能用,结果,我们遇到了一个WebDriverException的异常:selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Python安装Selenium3

很显然,异常中说的很明确,geckodriver需要在PATH中。我们如何解决呢?

其实,我们可以在网上搜索geckodriver,然后下载,把它放到一个PATH中即可。还有一种比较常用的方法就是:把错误信息复制一下,在网上搜索看看,世界这么大,99%有人遇到过同样的问题。

问题解决

我们把下载好的geckodriver.exe放在C:\Python27\Scripts目录下,再试一次。

有的朋友会问,为什么要放在C:\Python27\Scripts呢?这是因为个人比较懒,我知道c:\Python27\Scripts已经在PATH中了,这样我就不用再单独为geckodriver.exe设置PATH了。

Python安装Selenium3

是不是成功了呀?我是成功了,如下图:

Python安装Selenium3