该topic将开始学习selenium的使用。主要内容如下

  • 1.安装
  • 2.入门
  • 3.导航
  • 4.元素定位
  • 5.等待
  • 6.页面对象
  • 7.WebDriver API
  • 8.常见问题

安装

简介

Selenium&python提供了使用Selenium WebDriver编写功能/通过性测试的API。通过Selenium Python API可以直观的使用Selenium的功能。 Selenium&python提供了直观的API访问Selenium WebDrivers如firefox、ie、chrome、Remote等。目前支撑的python版本为2.7\3.2及以上。 本文只涉及Selenium 2 WebDriver.Selenium1没有覆盖。

下载Selenium python支持包

可以在PyPI page for selenium package下载Selenium python支持包。更好的方式是通过pip去安装,在python3.5已集成进标准库:

pip install selenium

可以考虑使用virtualenv创建的独立python环境。Python 3.5的pyvenv和virtualenv类似。

针对windows环境的说明

  • 1.安装python 3.5
  • 2.在cmd.exe命令行下,使用pip命令安装 C:\Python35\scripts\pip.exe install selenium

这样就可以运行python脚本,例如一个脚本放到C:\my_selenium_script.py,可以这样执行:

C:\Python35\python.exe C:\my_selenium_script.py

下载Selenium server

Selenium server是一个Java程序。建议使用JRE1.6或以上版本运行Selenium server. 可以从下载下载Selenium server2.x,文件名类似selenium-server-standalone-2.x.x.jar. 在此之前,确认系统中已经安装了JRE。 如果java支持,可以通过下面命令来启动Selenium server: java -jar selenium-server-standalone-2.x.x.jar

Top^

下一篇selenium-专题2>>>

by 李鹏