testUrl = 'http://www.baidu.com'
browser = Browser('chrome') #if you don’t provide any driver to Browser function, firefox will be used.
browser.visit(testUrl)
title = "测试页面:" + browser.title
print (title)
try:
browser.find_by_id('kw').fill('splinter test')
obj = browser.find_by_id('su').click()
time.sleep(0.2) #sleep0.2ms,主要目的是让browser更新其内部url变量
newurl = browser.url
print 'URL:', newurl #如果不加前面的sleep,url不会被更新,还是click之前的value
browser.visit(newurl) #重新visit一下新url,visit为阻塞函数
res = browser.html
open('d:\\test.html', 'w').write(res)
except Exception,x:
print (x)
if CLOASE_AFTER_TEST:
browser.quit()
本文转自 zhegaozhouji 51CTO博客,原文链接:http://blog.51cto.com/1038741/1758107