码迷,mamicode.com
首页 > 编程语言 > 详细

pythonweb自动化测试

时间:2015-02-01 14:44:47      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

from selenium import webdriver
import time


def capture(url, save_fn="capture.png"):
browser = webdriver.Firefox() # Get local session of firefox
browser.set_window_size(1200, 900)
browser.get(url) # Load page
browser.execute_script("""
(function () {
var y = 0;
var step = 100;
window.scroll(0, 0);

function f() {
if (y < document.body.scrollHeight) {
y += step;
window.scroll(0, y);
setTimeout(f, 50);
} else {
window.scroll(0, 0);
document.title += "scroll-done";
}
}

setTimeout(f, 1000);
})();
""")

for i in xrange(30):
if "scroll-done" in browser.title:
break
time.sleep(1)

browser.save_screenshot(save_fn)
browser.close()


if __name__ == "__main__":

capture("http://www.sohu.com")

 

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get(‘http://www.yahoo.com‘)
assert ‘Yahoo!‘ in browser.title

elem = browser.find_element_by_name(‘p‘)  # Find the search box
elem.send_keys(‘seleniumhq‘ + Keys.RETURN)

browser.quit()

pythonweb自动化测试

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4265528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!