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 webdriverfrom selenium.webdriver.common.keys import keysbrowser = Webdriver. Firefox () browser.get (' http://www.yahoo.com ') assert ' Yahoo! ' in Browser.titleelem = Browser.find_element_by_name (' P ' # Find The search boxelem.send_keys (' SELENIUMHQ ' + Keys.return) browser.quit ()
Pythonweb Automated Testing