一、所需工具

  1、Python3.6安装包

  2、Selenium安装包(selenium-server-standalone-3.8),如果是Python3的话可以不用下载selenium压缩包,Python3有自带的,直接输入命令安装即可

  3、Chromedriver驱动(Chromedriver2.3)

  4、Firefox驱动(geckodriver0.18)

  5、Chrome浏览器(chrome v.59)

  6、Firefox浏览器(Firefox v.54)

  7、Pycharm

  二、工具安装

  1、安装Python,安装完设置环境变量(将Python安装路径放入path下)

  2、selenium安装:cmd首先进入E:\Python\Scripts目录下,然后输入pip install -U selenium,等待安装完成即可

  3、pip安装:将pip工具包解压到指定盘,cmd命令进入该盘下,输入命令python setup.py install;再切换到E:\Python\Scripts 目录下输入E:\Python\Scripts > easy_install pip

  4、setuptools安装:将setuptools工具包解压到指定盘里,进入cmd,执行python ez_install.py即可

  5、将下载好的Chromedriver和geckodriver驱动放到Python安装路径下

  注意:Chromedriver和geckodriver驱动一定要和电脑上的浏览器版本对应,否则代码运行会报错

  Chromedriver和chrome浏览器对应版本

  代码:

  from selenium import webdriver

  import time

  # browser=webdriver.Chrome()

  browser=webdriver.Firefox()

  url='http://www.baidu.com'

  #通过get方法获取当前url打印

  print("now access %s" %(url))

  browser.get(url)

  time.sleep(2)

   browser.find_element_by_xpath("//input[@id='kw']").send_keys('Selenium')

  browser.find_element_by_id('su').click()

  # browser.find_element_by_css_selector("input[value$='下']")

  time.sleep(3)

  print("成功搜索")

  browser.quit()

  以上代码如果能正常运行说明环境配置成功

  PS:以下三个问题是安装过程中常遇到的坑

  遇到第一个坑:'geckodriver' executable needs to be in PATH

  1.如果启动浏览器过程中报如下错误

  Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__

  self.service.start()

  File "D:\test\python3\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start

  os.path.basename(self.path), self.start_error_message)

  selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

  2.这个是因为最新的selenium3.0启动firefox需要geckodriver.exe这个驱动文件。

  3.下载之后,配置到环境变量path下(可以直接放python根目录)

  遇到第二坑:Expected browser binary location, but unable to find binary in default location

  1.如果启动浏览器过程中报如下错误

  Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__

  keep_alive=True)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__

  self.start_session(desired_capabilities, browser_profile)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session

  response = self.execute(Command.NEW_SESSION, capabilities)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute

  self.error_handler.check_response(response)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response

  raise exception_class(message, screen, stacktrace)

  selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

  2.这个是因为firefox.exe这个文件也需要配置到环境变量path下

  3.这个路径就是安装完firefox后,找到firefox.exe这个文件的地址,加到path下

  遇到第三坑:Unsupported Marionette protocol version 2, required 3

  1.如果启动浏览器过程中出现如下错误

  Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__

  keep_alive=True)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__

  self.start_session(desired_capabilities, browser_profile)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session

  response = self.execute(Command.NEW_SESSION, capabilities)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute

  self.error_handler.check_response(response)

  File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response

  raise exception_class(message, screen, stacktrace)

  selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3

  2.这个错误原因是firefox版本过低了,最新的selenium3.0版本支持firefox47以上的版本,升级版本就可以了

Python3+Selenium环境配置的更多相关文章

  1. Python - Win10系统下Python3.x环境配置

    Win10系统下Python3.x环境配置 https://blog.csdn.net/qq_41952474/article/details/82630551

  2. C# selenium环境配置

    1.下载C#selenium     selenium官网:  http://www.seleniumhq.org/download/   下载后解压:     打开net35后,将里面的dll文件添 ...

  3. python+selenium环境配置及浏览器调用

    最近在学习python自动化,从项目角度和技术基础角度出发,我选择了python+selenium+appium的模式开始我的自动化测试之旅: 一.python安装 二.python IDE使用简介 ...

  4. selenium环境配置和八大元素定位

    一.环境配置 1.selenium下载安装 安装一:pip install selenium(多数会超时安装失败) 安装二:pip install -i https://pypi.tuna.tsing ...

  5. Python3爬虫环境配置

    一.包管理工具Anaconda安装 1.安装直接在官网下载最新版本的 https://www.continuum.io/downloads 2.配置环境变量PATH:C:\Users\Administ ...

  6. Python+Selenium 环境配置之Firefox,IE,Chrome几种浏览器运行

    Selenium(Webdriver)支持Firefox,IE,Chrome等多个浏览器.很多人可能装环境时遇到很多问题,下面简单聊聊如何配置测试这几个浏览器以及相关通过简单的实例来测试. 1.Fir ...

  7. 【Selenium】idea的selenium环境配置

    1.maven配置 下载地址:http://maven.apache.org/download.cgi# 下载内容:apache-maven-3.5.0-bin.zip 环境变量:M2_HOME:E: ...

  8. Java - Selenium 环境配置

    1. 安装Java JDK - 文件自己下 2. 配置环境变量-重要! 我的电脑-属性-高级-环境变量 添加 CLASSPATH  值 .;%JAVA_HOME%\lib;%JAVA_HOME%\li ...

  9. python+selenium 环境配置

    配置环境: python:3.5 selenium:3.3.0 安装方式:python pip install -u selenium windows: 10 firefox:52 因为firefox ...

随机推荐

  1. Roller5.0.3安装配置部署 step by step

    一.下载roller 下载地址:http://roller.apache.org/downloads/downloads.html下载下来之后,解压包含两部份doc.webapps 二.准备环境 1. ...

  2. linux每日命令(19):locate 命令

    locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...

  3. 【iCore4 双核心板_ARM】例程九:ADC实验——电源监控

    实验原理: STM32内部集成三个12位ADC,iCore1S的所有电源经过电阻分压或者直接 接入STM32的ADC的输出通道内,输入电流经过高端电流检测芯片ZXCT1009F 输入到ADC的输入通道 ...

  4. js中关于Blob对象的介绍与使用

    js中关于Blob对象的介绍与使用   blob对象介绍 一个 Blob对象表示一个不可变的, 原始数据的类似文件对象.Blob表示的数据不一定是一个JavaScript原生格式 blob对象本质上是 ...

  5. Java知多少(14)数组

    如果希望保存一组有相同类型的数据,可以使用数组. 数组的定义和内存分配 Java 中定义数组的语法有两种: type arrayName[]; type[] arrayName; type 为Java ...

  6. 关于Unity中NGUI的帧动画和Tween动画

    帧动画 1.把三张帧动画的贴图png制作成图集,NGUI---->Open---->Atlas Maker,生成一个预制体,一个材质球,一个大图 2.创建一个Sprite类型的Sprite ...

  7. 树莓派motion监控安装配置相关事情

    个人配置树莓派监控Motion相关的事情 from:http://www.cnblogs.com/zhaocundang/p/8870083.html 安装:apt-get install motio ...

  8. win7怎么打开加锁文件夹

    在windows 7下,C:\Documents and Settings文件夹是默认锁定的,很多时候要进入进行解除锁定,根据本人实践的经历略作介绍. 1.打计算机,进入c盘文件夹,2.分别点击“组织 ...

  9. [PHP] 01 - Hypertext Preprocessor

    超级文本预处理语言:http://php.net/ 集成的服务器组件,它已经包含了 PHP.Apache.Mysql 等服务 PHP 7 https://www.tutorialspoint. com ...

  10. [Android] 基于 Linux 命令行构建 Android 应用(三):构建流程

    Android 应用的构建过程就是将 Android 项目中的文件和资源进行编译和打包,最后将结果输出到 .apk 文件..apk 文件是保存二进制文件的容器,它包含了运行安卓应用所需的所有信息,例如 ...