1

Im trying to use selenium to clear a text field from a 'read only' input field.

This part of the code, although i don't get errors, it doesn't work:

from selenium.webdriver.common.keys import Keys
    enddate = driver.find_element_by_xpath('//*[@id="end"]')
    enddate.send_keys(" ")
    time.sleep(3)

I have also tried to do it by the element id, sending empty strings to the field, using clear() and it doesn't work. This is the field that I'm trying to clear on the UI (Im looking to clear the enddate field)

For testing, if I try to delete the value by modifying the HTML element on developer tools, then it works but it's not automated and does not use selenium.

Any advice on how I can accomplish this? Thanks

0

1 Answer 1

1

You need to remove the readonly attribute first:

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

from selenium.webdriver.common.keys import Keys
  end_date = driver.find_element_by_xpath('//*[@id="end"]')
  
  # Remove the attribute first: 
  driver.execute_script("arguments[0].removeAttribute('readonly')"), WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="end"]'))))

  end_date.send_keys(" ")
  time.sleep(3)
Sign up to request clarification or add additional context in comments.

1 Comment

This worked! , I just needed to clear() the input field after instead of sending an empty string. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.