0

How to clear the default data from a textbox using Python Selenium? I am getting element not interactable error.

HTML:

<div class="emailAttachmentInputMobile">
<input type="text" size="30" maxlength="100" ng-model="emailAttachmentRecipient" class="ng-pristine ng-valid ng-valid-maxlength ng-not-empty ng-touched">
</div>

This is my python code:

DeleteText  = driver.find_element_by_xpath("//input[@ng-model='emailAttachmentRecipient'][@type='text']").clear()

Whenever I run this I am getting "Element not interactable" error.

Could someone please help me resolve this issue. I have lost so much of my time to fix this issue but still am not able to fix.

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

1 Answers1

0

You need to consider a couple of things as follows:

  • clear() doesn't returns anything. So DeleteText will be always NULL.

  • The desired element is a Angular element, to clear the existing text 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, "div.emailAttachmentInputMobile input.ng-pristine.ng-valid.ng-valid-maxlength.ng-not-empty.ng-touched[ng-model='emailAttachmentRecipient']"))).clear()
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='emailAttachmentInputMobile']//input[@class='ng-pristine ng-valid ng-valid-maxlength ng-not-empty ng-touched' and @ng-model='emailAttachmentRecipient']"))).clear()
      
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have tried using both locator strategies but am getting the error "Ordinal0 [0x00E59943+2595139]... Ordinal0 [0x00E011FC+2232828] BaseThreadInitThunk [0x769DFA29+25] RtlGetAppContainerNamedObjectPath [0x770C7A9E+286] RtlGetAppContainerNamedObjectPath [0x770C7A6E+238]" – sow Mar 09 '22 at 15:07
  • Sounds like a different error all together and [Element not interactable](https://stackoverflow.com/a/54759731/7429447) error seems to have got resolved. Feel free to raise a new question with your new requirement. – undetected Selenium Mar 09 '22 at 15:19
  • This is the error raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: – sow Mar 09 '22 at 15:22