演示的版本信息如下:

Python 3.6.0

Selenium  3.5.0

Firefox 55.0.3

geckodriver v1.0.18.0 win64

1、前提准备

1.1 安装python
1.2 安装Firefox浏览器
1.3下载geckodriver(是Firefox的官方webdriver)

2、Python安装selenium

python 3.0X包自带pip和setuptools。我们可以使用如下方法安装selenium:
pip install selenium [version] 如果不加版本号,就安装最新的。加了就安装指定版本
如果在安装过程中,遇到如下错误,需要单独安装pip和setuptools:
下载地址:https://pypi.python.org/pypi/pip/#downloads
                 https://pypi.python.org/pypi/setuptools#downloads
安装方式如下图所示:
安装setuptools
安装pip
安装完成之后,可以检查selenium的安装:

3、 下载安装geckodriver

下载地址:https://github.com/mozilla/geckodriver/releases
根据电脑系统版本进行下载,我这里下载的win64位的:
下载完成后,解压,将geckodriver.exe放置在与python3.exe相同的路径下:
   
注意:
这里之所以将geckodriver.exe与Python3.exe放置在相同路径下,是因为python3.exe在系统的环境变量中的Path中有配置:【D:\Program
Files\Python36\】。如果不放置到相同路径,需要自己在Path中配置环境变量,路径为geckodriver所在路径。

4、访问页面

selenium进行自动化测试的方法是打开浏览器,按照脚本规定的操作模拟人的行为,然后检查期望值与实际值是否相符,以判定测试是否通过。所以第一步就是:访问页面。
如下图脚本,是使用Firefox访问百度首页:

5、PyCharm配置Selenium

这里使用PyCharm来运行以上脚本。需要在PyCharm里面配置Selenium。
进入File-Settings:
选择我们的项目,点击Project Interpreter,点击右侧的+:

6、运行代码

最后运行代码,就可以了。

python selenium firefox使用的更多相关文章

  1. 配置Python+selenium+firefox自动化测试

    1.安装python.默认安装 2.安装pip.下载pip-1.5.4包,解压pip-1.5.4,放在C盘,进入pip目录-->键入命令:python setup.py install  再进入 ...

  2. python+selenium+Firefox+pycharm版本匹配

    window(2018-05-29)最新 python:3.6.1    地址https://www.python.org/downloads/release/python-361/ selenium ...

  3. Windows上python + selenium + Firefox浏览器的环境配置

    1.python安装 我的电脑是32位的,安装了Python 3.5.4版本其它安装版本 2.python环境变量配置 将”C:\Program Files\Python35",”C:\Pr ...

  4. 在Centos7上安装Python+Selenium+Firefox+Geckodriver

    1.事先准备好Centos7的系统 Centos系统是CentOS Linux release 7.4.1708 (Core) 查看Centos内核版本命令cat /etc/centos-releas ...

  5. Python selenium + Firefox启动浏览器

    Python selenium 的运用 from selenium import webdriver # from selenium.webdriver.firefox.firefox_profile ...

  6. 在Centos7下安装Python+Selenium+Firefox学习环境

    Selenium 一自动化测试工具.它支持 Chrome,Safari,Firefox 等主流界面式浏览器,如果你在这些浏览器里面安装一个 Selenium 的插件,那么便可以方便地实现Web界面的测 ...

  7. python selenium firefox 添加cookie add_cookie

    from selenium import webdriver driver = webdriver.Firefox() driver.get('http://www.baidu.com') cooki ...

  8. 在Centos7上安装Python+Selenium+Chrome+Chromedriver

    1.下载Chrome 上一篇文章已经演示过了Python+Selenium+Firefox+Geckodriver安装步骤并通过自动化脚本打开百度 因此当前只需要安装Chrome和Chromedriv ...

  9. selenium+python启动Firefox浏览器失败问题和点击登陆按钮无效问题

    问题1:使用python+selenium编写脚本调用Firefox时报错:

随机推荐

  1. linux常用指令--防火墙

    centos7 iptables :  如果你想使用iptables静态路由规则,那么就禁用centos7默认的firewalld,并安装ipteables-services, 启用iptables和 ...

  2. 去掉点击map时的显示area边框

    cus="true"的属性即可 如下: <img src="some.jpg" border="0" usemap="#ma ...

  3. Hadoop分布式文件系统--HDFS结构分析

    转自:http://blog.csdn.net/androidlushangderen/article/details/47377543 HDFS系列:http://blog.csdn.net/And ...

  4. 网络协议之ts---ts 流分析详解

    名词缩写翻译: es:elements stream 基本流 pes:packet elements stream 打包流 pts:presentation time stamp 显示时间戳 dts: ...

  5. jenkins配置svn、gradle、ssh

    1.先说下实现的效果,从svn拉取代码.调用gradle编译构建.将构建包分发到部署服务器并备份原来的部署包: 2.直接从http://mirrors.jenkins-ci.org/war/lates ...

  6. java获取系统时区

    //Calendar cal = Calendar.getInstance(); //TimeZone timeZone = cal.getTimeZone(); TimeZone timeZone ...

  7. MVC [Control与View交互]

    <1> Home控制器 using System; using System.Collections.Generic; using System.Data; using System.Da ...

  8. Linux系统优化之网络IO调优

    修改 vi /etc/sysctl.conf后执行命令 sysctl -p立即生效 首先,系统的不同也会导致 /etc/下的 文件的不同,原本powerpc 环境下 在 /etc/init.d/下有个 ...

  9. 编写高质量代码--改善python程序的建议(一)

    原文发表在我的博客主页,转载请注明出处! 初衷 python是一个入门十分容易的编程语言,但是想要写好python却是一件不容易的事情,如果不是专业使用python的人,只是将python作为一个脚本 ...

  10. 《挑战程序设计竞赛》2.3 动态规划-进阶 POJ1065 1631 3666 2392 2184(5)

    POJ1065: Description There is a pile of n wooden sticks. The length and weight of each stick are kno ...