本文共 1033 字,大约阅读时间需要 3 分钟。
网上查资料无意中看见这个东西,觉得挺好玩,原来是用来做web测试的。于是安装了个玩玩python的官网中居然有这个介绍:http://pypi.python.org/pypi/selenium
简单介绍下虚拟环境(为了方便安装各种包,又不会影响系统包)
建立虚拟环境
virtualenv example (创建)
启用
source example/bin/activate
pip install selenium (这样就装好了)
离开
deactivate
测试例子:
from selenium import webdriverfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.webdriver.common.keys import Keysimport timebrowser = webdriver.Firefox() # Get local session of firefoxbrowser.get("http://www.yahoo.com") # Load pageassert "Yahoo!" in browser.titleelem = browser.find_element_by_name("p") # Find the query boxelem.send_keys("seleniumhq" + Keys.RETURN)time.sleep(0.2) # Let the page load, will be added to the APItry: browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")except NoSuchElementException: assert 0, "can't find seleniumhq"browser.close()
运行的结果是打开雅虎浏览器搜素seleniuhq,然后查找http://seleniumhq.org
http://www.ltesting.net/ceshi/open/kygncsgj/selenium/
再补充下介绍,要下班了,明天慢慢看
Selenium (SeleniumHQ) 是 thoughtworks公司的一个集成测试的强大工具。
转载地址:http://savws.baihongyu.com/