Skip to content Skip to sidebar Skip to footer

Selenium Won't Type To Textarea And Raises Elementnotinteractableexception

This is the HTML code in question: This is my code: msgElem = driver.find_element_by_css_selector('textar

Solution 1:

This error message...

ElementNotInteractableException

...implies that the WebDriver instance was unable to interact with the desired element as the Element was Not Interactable.


Analysis

The Locator Strategy which you have used actually identifies two elements within the HTML DOM and the parent element of the first matching element contains the attribute style="display:none" as follows:

<formaction="#"class="usertext cloneable warn-on-unload"onsubmit="return post_form(this, 'comment')"style="display:none"id="form-dyo"><inputtype="hidden"name="thing_id"value=""><divclass="usertext-edit md-container"style=""><divclass="md"><textarearows="1"cols="1"name="text"class=""></textarea></div>

Hence you see ElementNotInteractableException.


Solution

To send a character sequesce to the desired element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.title + divtextarea[name='text']"))).send_keys("Sowik")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='message']//following::div[1]//textarea[@name='text']"))).send_keys("Sowik")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

Post a Comment for "Selenium Won't Type To Textarea And Raises Elementnotinteractableexception"