1

I use python + selenium to add some text into the text area (in DOM it is a DIV tag).

For example, I have the following text:

EVERY SINGLE picture or video you will publish with

after using send_keys() function the text inside textarea became following:

EVERY SINGLE ice o ideo o ill blih ih

Code snippet:

message = 'EVERY SINGLE picture or video you will publish with'
reply_input = WebDriverWait(driver, 10).until(
                                    EC.presence_of_element_located((By.CSS_SELECTOR, 'div[aria-label="Message Body"]'))
                                )
reply_input.clear()
reply_input.click()
reply_input.send_keys(message)

The problem is, that the issue not stable to reproduce, it appears from time to time.

Does anyone know how to solve such a problem?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Roman
  • 1,883
  • 2
  • 14
  • 26

1 Answers1

-1

presence_of_element_located() doesn't ensures that the element is interactable. Instead you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

message = 'EVERY SINGLE picture or video you will publish with'
reply_input = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[aria-label="Message Body"]")))
reply_input.click()
reply_input.clear()
reply_input.send_keys(message)

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Reference

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352