0

When I click on the link in the Telegram, a window appears

Photo of problem


How do I press the "Отмена" button using selenium?

I tried to solve the problem with 'selenium alert' but nothing works

from selenium import webdriver
import undetected_chromedriver as uc
import time


options = webdriver.ChromeOptions()
driver = uc.Chrome(options=options)

driver.get('https://t.me/rian_ru')

time.sleep(2)

try:
    alert = driver.switch_to.alert
    alert.accept()
    print("alert accepted")
except:
    print("no alert")
0stone0
  • 34,288
  • 4
  • 39
  • 64
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jun 07 '23 at 15:08

1 Answers1

0

After searching and reading for a long time, I finally found a way to bypass that confirmation using Selenium 4.9.

All the duplicate questions are outdated, or simply wrong at all!


The reason why driver.switch_to.alert doesn't work is because it's a OS alert, not a Chromium alert().


You can pass a chrome option that will allow some protocols on a specific url

chrome_options = webdriver.ChromeOptions()

chrome_options.add_experimental_option("prefs", {
    "protocol_handler": {
        "allowed_origin_protocol_pairs": {
            "https://t.me": { "tg": True }
        }
    }
})

driver = webdriver.Chrome(FILL_THIS_YOURSELF, options=chrome_options)

driver.get('https://t.me/some-fancy-user-name')

This tells Chromium to allow 'tg://' protocols to be handled on https://t.me websites, without any confirmation.

0stone0
  • 34,288
  • 4
  • 39
  • 64