Pythonweb Automated Testing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.