#This script generates screenshots for HEN NGRTM2 model network htm files
#author: Vilem Knap
import selenium
import time
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from time import sleep
#Create list of htm files
# folder path
input_filepath = r'C:\\Users\\kna99391\\M036 Prepare Alt Supply Scenario Forecast Networks\\Checks\\Core\\'
# list to store files
files_list = []
# Iterate directory
for file in os.listdir(input_filepath):
# check only text files
if file.endswith('.htm'):
files_list.append(file)
#print(files_list)
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)
wait = WebDriverWait(driver, 10)
#Specify the folder where the exported screenshots will be stored
output_filepath = r'C:\\Users\\kna99391\\M036 Prepare Alt Supply Scenario Forecast Networks\\Checks\\Snapshots\\'
for i in range(len(files_list)):
output_filename = files_list[i][:-4]
driver.get(input_filepath+files_list[i])
find_elem = None
scroll_from = 0
sleep(2)
driver.execute_script("window.scrollTo(%d, %d);" %(scroll_from, scroll_from+300))
driver.save_screenshot(output_filepath+output_filename+"_1.png")
#scroll_limit = 1000
driver.execute_script("window.scrollTo(%d, %d);" %(scroll_from, scroll_from+1300))
driver.save_screenshot(output_filepath+output_filename+"_2.png")
#scroll_limit = 3000
driver.execute_script("window.scrollTo(%d, %d);" %(scroll_from, scroll_from+3000))
driver.save_screenshot(output_filepath+output_filename+"_3.png")
driver.close()