Selenium - 滚动屏幕截图

Selenium - Scroll for screenshots

我有一个 python 脚本,它遍历 UI 并填写了很多页面。我截图了,但是如果页面比屏幕长,那么我会漏掉一半页面。我尝试了更长的长度,但对于普通页面,它很荒谬且无法使用。我尝试使用 ashot,但无法弄清楚如何将它添加到我在 pycharm.

中的项目中

有什么智慧或其他想法吗?谢谢

更新已尝试但无效的内容(页面上没有任何反应:

actions = ActionChains(driver)
actions.move_to_element(continuebtn)

还有:

chrome_options.add_argument('--enable-javascript')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, 1080);")

您可以截取多个屏幕截图并滚动浏览整个页面。

一个简单的例子是:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.options import Options
import time

d = webdriver.Firefox(executable_path="PATH TO YOUR DRIVER")
d.get("https://en.wikipedia.org/wiki/HTTP_cookie")
time.sleep(1)
scrollHeight = d.execute_script("return window.scrollMaxY")
index = 0
while d.execute_script("return window.pageYOffset") < scrollHeight:
    d.save_screenshot(PICTURE_PATH+"/"+ FILENAME + str(index).zfill(2) + ".png")
    d.execute_script("window.scrollByPages(1)")
    # maybe call time.sleep in here somewhere to load lazyloaded images
    time.sleep(0.2)
    index += 1
d.quit()