1

I have a python script that goes through the UI and fills out a lot of pages. I take a screenshot, but if the page is longer than the screen, then I miss half of the page. I tried a longer length, but with the normal pages, it's ridiculous and unusable. I tried to use ashot, but can't figure out how to add it to my project in pycharm.

Any wisdom or other ideas? Thanks.

UPDATE on things tried that didn't work (nothing happened on the page:

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

Also:

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

1 Answers1

1

You could take a multiple screenshots and scroll through the whole page.

A simple example would be:

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()
NationBoneless
  • 308
  • 2
  • 12
  • I tried the following (where driver is my chrome browser instance) just to see if I can get it to scroll a page and nothing happens on the page: driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") – Brandy Jan 26 '21 at 20:35
  • Have you tried this method with firefox? Alternatively have you tried adding javascript manually in the options (see [https://stackoverflow.com/questions/55480924/how-to-enable-javascript-in-selenium-webdriver-chrome-using-python](https://stackoverflow.com/questions/55480924/how-to-enable-javascript-in-selenium-webdriver-chrome-using-python) ) – NationBoneless Jan 26 '21 at 21:05
  • We don't use firefox. Chrome and IE only. I'll check out the link - thanks! – Brandy Jan 27 '21 at 15:32
  • The two items on that link didn't work. One made no change and one caused an error. Thanks though :/ – Brandy Jan 27 '21 at 15:44
  • 1
    I think I got it working! I had to click elsewhere on the page for it to actually work. – Brandy Jan 27 '21 at 20:38