Splinter¶
Splinter 是用 Python 开发的一个开源web自动化测试的工具集。 它可以帮你自动化浏览器的行为,比如浏览 URLs 并和页面进行交互。
简单的例子¶
from splinter import Browser
with Browser() as browser:
# 访问 URL
url = "http://baidu.com"
browser.visit(url)
browser.fill('wd', 'splinter - python acceptance testing for web applications')
# 找到并点击搜索按钮
button = browser.find_by_xpath('//input[@type="submit"]')
# 与元素交互
button.click()
if browser.is_text_present('splinter.readthedocs'):
print "Yes, the official website was found!"
else:
print "No, it wasn't found... We need to improve our SEO techniques"
注意: 如果你不为 Browser
指定 driver, 那么会默认使用 firefox
。
特点¶
- 简单的 api
- 支持多种 webdriver (chrome webdriver, firefox webdriver, phantomjs webdriver, zopetestbrowser, remote webdriver)
- 支持 css 和 xpath 选择器
- 支持 iframe 和 alert
- 可执行 javascript 脚本
- 支持 ajax 和 异步 javascript
开始上手¶
支持 JavaScript¶
Drivers¶
常用浏览器 drivers¶
The following drivers open a browser to run your actions:
无界面浏览器 drivers¶
The following drivers don’t open a browser to run your actions (but has its own dependencies, check the specific docs for each driver):
远程 driver¶
The remote driver uses Selenium Remote to control a web browser on a remote machine.