'selenium modify html read only input element with python?
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
Solution 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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |