1、selenium简介
selenium是一个开源的自动化框架,他可以让你在各种语言中实现webui自动化测试,比如:C、java、ruby、python、C#等等;并且支持跨平台,windows linux mac;同时支持多浏览器,ie、ff、safari、opera、chrome,只需要加载对应的驱动即可;
还能支持分布式测试执行,将TestCase分发到不同的执行机同时执行,提高执行效率;
2、selenium环境安装
selenium安装比较简单,包括三部分:
selenium相关、python相关、浏览器相关
2.1 selenium安装
selenium安装:pip install selenium
2.2 python安装
python 安装推荐3.7版本比较稳定,且相匹配的库也比较成熟,不推荐安装最新的版本
python 代码编辑器,推荐PyCharm,个人觉得比较好用
2.3 chrome安装
chrome浏览器下载,目前我使用的是81版本,最好不要使用最新的chrome可能对应的chromedriver不好找
https://download.csdn.net/download/BenZ_X/88492180
chromedriver下载CNPM Binaries Mirror;可根据自己安装的chrome浏览器版本,下载对应版本的chromedriver
将下载的chromedriver放入python安装目录下
3、安装完成后的测试验证
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.find_element(By.ID,"kw").send_keys("selenium")
driver.find_element(By.ID,"su").click()
time.sleep(11)
driver.quit()