简体   繁体   中英

Selenium firefox driver take window screenshot(not fullscreen)

I have a fully working Python script for taking screenshots of webpages using selenium and the FF driver(windows).

The script is taking full page screenshots instead of let's say 1024x768, which make the process slow. Here is my code:

    driver = webdriver.Firefox()
    driver.set_window_size(1024,768)
    driver.get(url)
    driver.get_screenshot_as_file("%s/%s.png"%(screen_dir,o.netloc))
    driver.close()

Any ideas on how to make selenium/firefox take above the fold screenshots and not full page?

Thanks!

This is how the "take screenshot" functionality is working in Firefox - it would take a screenshot of a complete page from top to bottom even if part of it is not visible. This is actually not how it supposed to work by the specification .

Chrome would take a screenshot of the visible area / viewport only . Switch to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM