I have written an automated script to open the Control Pannel and get information about the “Programs and Features” I want the Screenshot to be taken of the full output displayed. But for that I need the scrollbar to scroll then take a Screenshot then Again Scroll take a screenshot
import subprocess
import os
import pyautogui
import pygetwindow as gw
from PIL import Image
import time
def maximize_window(title):
windows = gw.getWindowsWithTitle(title)
if windows:
window = windows[0]
window.maximize()
window.activate()
print(f"Maximized and activated window: {title}")
else:
print(f"No window found with title: {title}")
def capture_screenshots(folder, prefix, scroll_delay=0.5):
if not os.path.exists(folder):
os.makedirs(folder)
screenshot_index = 0
previous_screenshot = None
screen_width, screen_height = pyautogui.size()
while True:
# Ensure the window is in focus
window = gw.getWindowsWithTitle("Programs and Features")[0]
window.activate()
screenshot_path = os.path.join(folder, f"{prefix}_{screenshot_index}.png")
pyautogui.screenshot(screenshot_path)
print(f"Captured screenshot: {screenshot_path}")
screenshot_index += 1
pyautogui.scroll(200)
time.sleep(scroll_delay)
current_screenshot = Image.open(screenshot_path)
# Break if the bottom of the window is reached by comparing the last two screenshots
if previous_screenshot:
if list(previous_screenshot.getdata()) == list(current_screenshot.getdata()):
print("Reached the bottom of the window.")
break
previous_screenshot = current_screenshot
def open_programs_and_features():
try:
# Open Control Panel directly to Programs and Features
subprocess.run(['control', 'appwiz.cpl'])
print("Opened Programs and Features.")
except subprocess.CalledProcessError as e:
print(f"An error occurred while trying to open Programs and Features: {e}")
if __name__ == "__main__":
open_programs_and_features()
time.sleep(5)
maximize_window("Programs and Features")
time.sleep(1)
capture_screenshots(folder="screenshots", prefix="programs_and_features")
I have written pyautogui.scroll(200) but the application is not scrolling. I also tried pyautogui.scroll(-screen_height) still not working.