2

I'm trying to remove readonly tag from an input field by using python and selenium. Can anybody help me here?

Datepicker Image:

date

HTML:

<input id="startDate" name="START_DATE" type="text" class="date hasDatepicker" readonly="readonly">

Code I've tried :

driver.execute_script('driver.find_element_by_xpath('"+//*[@id = '"+'startDate'+"']+"').removeAttribute("readonly")')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Franc
  • 31
  • 4
  • What happens when you run that piece of code? Also, do you want to remove both `readonly="readonly"` or just attribute value ? – cruisepandey Dec 04 '21 at 09:41
  • I'll need to remove both so that i can place in inputs that is why. Thank You. – Franc Dec 04 '21 at 10:13

1 Answers1

1

To remove the readonly attribute you need to use removeAttribute() as follows:

element = driver.find_element(By.XPATH, "//input[@class='date hasDatepicker' and @id='startDate']")
driver.execute_script("arguments[0].removeAttribute('readonly')", element)

References

You can find a couple of relevant detailed discussions in:

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