Search code examples
pythonseleniumcontenteditablesendkeyswebdriverwait

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while sending text to contenteditable div element


I am having trouble with a selenium send keys on discord. I am attempting to send a message to a user.

The error I get is:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

The HTML is as follows: HTML

The Object im trying to send_keys that is highlighted by the xpath is as follows: enter image description here

My code is as follows

inputMessage = wait.until(EC.visibility_of_element_located((By.XPATH,"//div[contains(text(),'Message @')]/..")))

#inputMessage = driver.find_element_by_xpath("//div[contains(text(),'Message @')]/..") 

inputMessage.send_keys(msg,Keys.ENTER) 

I have attempted several ways to try to solve the error but have not succeeded. Any help would be appreciated. Thank you.


Solution

  • The ElementNotInteractableException error tells you that you can't use the send_keys() method on this webElement. I can't really tell you what could work, considering the lack of information considering the problem, but here are some clues :

    • Using the ActionsChains to try to input what you want in the field:
    from selenium.webdriver.common.action_chains import ActionChains
    actions = ActionChains(self.driver)
    actions.send_keys('your_data')
    actions.perform()
    
    • Try inputMessage.click() before you try to send keys

    Otherwise, it happened to me too, and the thing was that i tried to send keys to the div, and not to the element which was inside it.

    Hopes it help !