The bot sends me a screenshot message with promo code activation, and 4 buttons are created under the message, namely 1-4, and each button executes its own script in Chromium, but for some reason the buttons are not working from selenium.webdriver.support.wait import WebDriverWait as WB from pyrogram import Client, types, filters from pyrogram.handlers import MessageHandler, callback_query_handler from aiogram import Bot import shutil import subprocess import undetected_chromedriver as uc import requests import os import re import time import logging
def get_id_session(app: Client):
#doesnt matter
def init_driver(headless: bool):
#doesnt matter
def get_domen():
#doesnt matter
def open_web_site(driver: uc.Chrome):
#doesnt matter
async def send_notify(promocode: str, result: float, balance: int):
#keybo
reply_markup = types.InlineKeyboardMarkup([
[
types.InlineKeyboardButton("Button 1", callback_data="0"),
types.InlineKeyboardButton("Button 2", callback_data="1"),
],
[
types.InlineKeyboardButton("Button 3", callback_data="2"),
types.InlineKeyboardButton("Button 4", callback_data="3"),
],
])
await bot.send_photo(
chat_id=sender_id,
photo=open('temp.png', 'rb'),
caption=f'Activation statistics :\n\n'
f'*Total activation time : *{result}'
f'*Actual balance : *{balance}',
parse_mode='Markdown',
reply_markup=reply_markup
)
os.remove('temp.png')
#handler
async def button_handler(client: Client, callback_query: types.CallbackQuery):
button_id = int(callback_query.data)
logging.info(f'A button with a number is pressed {button_id}')
if button_id == 0:
driver.execute_script('document.querySelectorAll("div.captcha__variants > button")[0].click()')
elif button_id == 1:
driver.execute_script('document.querySelectorAll("div.captcha__variants > button")[1].click()')
elif button_id == 2:
driver.execute_script('document.querySelectorAll("div.captcha__variants > button")[2].click()')
elif button_id == 3:
driver.execute_script('document.querySelectorAll("div.captcha__variants > button")[3].click()')
elif button_id == 4:
driver.execute_script('document.querySelectorAll("div.captcha__variants > button")[3].click()')
await callback_query.answer()
def activate_promocode(promocode: str, driver: uc.Chrome):
#doesn't matter
async def get_promo_handler(client: Client, message: types.Message):
#doesn't matter
if __name__ == "__main__":
print('Меню:\n1. Run the script.\n2. Account authorization.\n3. Clear the script cache.\n4. End all script processes.')
_func = input('\nEnter the function you need - ')
subprocess.call('taskkill /f /im chrome.exe', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.call('taskkill /f /im undetected_chromedriver.exe', stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if _func == '1':
baza_promocode = []
driver = init_driver(False)
open_web_site(driver)
channels = [-100184339344, -1001348070579, -1001686106961, -1001680254374]
try:
with open("files\\channels.txt", "r", encoding='utf8') as f:
if read := f.read():
for channel in read.strip().split('\n'):
channels.append(int(channel))
except FileNotFoundError:
open('files\\channels.txt', 'w').close()
app = Client("files\\session", api_id=#doesn't matter, api_hash='#doesn't matter')
bot = Bot(bytes(
[54, 51, 15, 65, 70, 90, 90, 115, 82, 118, 76, 111, 122, 113, 75, 95, 118,
69, 76, 112, 111, 95, 114, 103, 48, 112, 45, 78, 87, 102, 95, 71, 115, 67, 53, 110, 107]).decode())
with app:
sender_id = get_id_session(app)
app.add_handler(MessageHandler(get_promo_handler, filters=filters.chat(list(map(int, channels)))))
app.add_handler(lambda client, callback_query: callback_query_handler(client, callback_query, button_handler))
print('Detected authorization, launched successfully.')
app.run()
if _func == '2':
#doesn't matter
if _func == '3':
#doesn't matter
if _func == '4':
#doesn't matter
input('\nExit')
i tried different ways to fix this trouble