言简意赅的说下Selenium是什么html
Selenium是前台测试框架,支持IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome等浏览器,我只试了这四个,别的你们用的时候能够试下。python
用脚本能够模拟网页的点击,输入,提交,验证等操做。git
可参照下列网站进行学习:github
1.https://selenium-python-zh.readthedocs.io/en/latest/installation.html(中文)web
2.https://selenium-python.readthedocs.io/index.html(英文)浏览器
安装/运行Demo:框架
1.Python官方网站下载最新版Python学习
https://www.python.org/downloads/测试
2.经过pip下载安装Selenium网站
也能够直接进入Python的Scripts目录,按住Shift+鼠标右键,选择PowerShell窗口。
注意有提示升级Pip的时候根据命令升级你的PIP
D:\>cd D:\python\Scripts D:\python\Scripts>pip install selenium
3.查看Selenium版本
D:\python\Scripts>pip show selenium Name: selenium Version: 3.14.1 Summary: Python bindings for Selenium Home-page: https://github.com/SeleniumHQ/selenium/ Author: UNKNOWN Author-email: UNKNOWN License: Apache 2.0 Location: d:\python\lib\site-packages Requires: urllib3 Required-by: D:\python\Scripts>
4.下载火狐Firefox的驱动geckodriver 下载地址:https://github.com/mozilla/geckodriver/releases/
注意版本,下载完成后将geckodriver.exe放到Python的安装目录下。个人是D:\Python,而后将D:\Python添加到系统的环境变量中
5.编写脚本
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
print (driver.title)
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
6.运行Demo
D:\python>python 目录\testPython.py
Welcome to Python.org
D:\python>
已上只是跑一个简单的Demo,你们也能够下载Selenium的IDE进行工做更方便。