У меня есть код, который запускает 2 браузера вместе и делает скриншот, но есть проблема, когда я хочу брать скриншоты двух окон, то берется скриншот окна, которое открыто, а то, которое свёрнуто, не берётся. Кто знает, как это исправить?
Вот пример кода
import eel
import asyncio
from keyauth import api
import sys
import time
import platform
import os
import hashlib
from time import sleep
from datetime import datetime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
import undetected_chromedriver as uc
import json
import pyautogui
import pyautogui as pag
import re
from plyer import notification
import telebot
import threading
bot = telebot.TeleBot('')
SPECIFIC_USER_ID = ''
is_restarting = False
def set_auth_token(driver, token):
script = f'window.localStorage.setItem("authToken", "{token}");'
driver.execute_script(script)
def start_browser(token):
print("Starting Selenium...")
bot.send_message(SPECIFIC_USER_ID, f"Start browser with token: {token}")
target_path = os.path.dirname(os.path.abspath(__file__))
options = uc.ChromeOptions()
options.add_argument(f'--load-extension={target_path}/Captcha_Solver')
time.sleep(2)
driver = uc.Chrome(options=options)
time.sleep(1)
driver.switch_to.window(driver.window_handles[1])
time.sleep(8)
driver.close()
driver.switch_to.window(driver.window_handles[0])
driver.execute_script("window.open('site.gg', '_blank')")
time.sleep(10)
driver.switch_to.window(driver.window_handles[1])
set_auth_token(driver, token)
driver.get('site.gg')
bot.send_message(SPECIFIC_USER_ID, "Reloading page")
print("Reloading page...")
time.sleep(5)
driver.get_screenshot_as_file('Browser.png')
photo_path = 'Browser.png'
with open(photo_path, 'rb') as photo:
bot.send_photo(SPECIFIC_USER_ID, photo)
return driver
def start_timer():
for item in tokens_webhooks:
token = item["token"]
thread = threading.Thread(target=monitor_rain, args=(token,))
# Start the thread
thread.start()
time.sleep(35)
def monitor_rain(token):
driver = start_browser(token)
while True:
if is_restarting:
time.sleep(1)
continue
try:
time.sleep(5)
driver.get_screenshot_as_file('screen.png')
time.sleep(1)
except Exception as e:
print(f"An error occurred: {e}")
time.sleep(1)
tokens_webhooks = [
{"token": "",},
{"token": "",},
]
def start_bot():
bot.polling()
if __name__ == '__main__':
bot_thread = threading.Thread(target=start_bot)
bot_thread.daemon = True
bot_thread.start()
start_timer()