telegram web text area el for selenium

Рейтинг: 0Ответов: 1Опубликовано: 02.03.2023

Пытаюсь выдать селениуму 4 - элемент(div) ввода текста смс в telegram

find_element(By.CSS_SELECTOR, '.input-message-input'):

он ругается в терминале

if driver.find_element(By.CSS_SELECTOR, '.input-message-input'):
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Больше кода:

driver = webdriver.Chrome('C:\\chromedriver.exe')
driver.get('https://web.telegram.org/*******')
while True:
    current_url = driver.current_url
    if current_url == 'https://web.telegram.org/*******':
        print("current url")
        if driver.find_element(By.CSS_SELECTOR, '.input-message-input'):
            print('found')
    if current_url != 'https://web.telegram.org/*******':
        print('not current url')
    time.sleep(10) 

Прицепить пытаюсь поле для ввода смс в телеграме, который где-то тут:

<div class="input-message-container"><div class="input-message-input i18n scrollable scrollable-y no-scrollbar" contenteditable="true" dir="auto" data-placeholder="Message" tabindex="-1" data-peer-id="-*******" style="transition-duration: 0ms; height: 37px;"></div><div contenteditable="true" tabindex="-1" class="input-message-input i18n scrollable scrollable-y no-scrollbar input-field-input-fake"></div></div> 

Ошибки:

Traceback (most recent call last):
  File "c:\Users\user\Desktop\bot\bot.py", line 17, in <module>
    if driver.find_element(By.CSS_SELECTOR, '.input-message-input'):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1238, in find_element
    return self.execute(Command.FIND_ELEMENT, {

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".input-message-input"}
  (Session info: chrome=110.0.5481.178)
Stacktrace:
Backtrace:
        (No symbol) [0x011A37D3]
        (No symbol) [0x01138B81]
        (No symbol) [0x0103B36D]
        (No symbol) [0x0106D382]
        (No symbol) [0x0106D4BB]
        (No symbol) [0x010A3302]
        (No symbol) [0x0108B464]
        (No symbol) [0x010A1215]
        (No symbol) [0x0108B216]
        (No symbol) [0x01060D97]
        (No symbol) [0x0106253D]
        GetHandleVerifier [0x0141ABF2+2510930]
        GetHandleVerifier [0x01448EC1+2700065]
        GetHandleVerifier [0x0144C86C+2714828]
        GetHandleVerifier [0x01253480+645344]
        (No symbol) [0x01140FD2]
        (No symbol) [0x01146C68]
        (No symbol) [0x01146D4B]
        (No symbol) [0x01150D6B]
        BaseThreadInitThunk [0x752BFA29+25]
        RtlGetAppContainerNamedObjectPath [0x773E7A9E+286]
        RtlGetAppContainerNamedObjectPath [0x773E7A6E+238]

Ответы

▲ 0

Моя ошибка заключалась в том ,что я просматривал элементы в версии web telegram "k", в то время как selenuim открывал мне версию "z" где в свою очередь другой dom.