Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python selenium sending keys to readonly text box

I am trying to send keys to the below field using below python selenium code

<input type="text" name="date_startDateSql" readonly="" class="EditableRequiredField" onfocus="setday(this)">

Selenium Python Code :

element=driver.find_element_by_name('date_startDateSql') element.send_keys('12/10/2017')

I am not getting any error or exception but not able to send keys into this element.I am new to python selenium and would appreciate if someone could advise how to send keys to the fields that are readonly.

like image 865
Sreeharsha Kasturi Avatar asked Feb 04 '23 04:02

Sreeharsha Kasturi


2 Answers

Remove the readonly attribute of your input before sending keys :

driver.execute_script('document.getElementsByName("date_startDateSql")[0].removeAttribute("readonly")')
like image 119
Antikhippe Avatar answered Feb 06 '23 18:02

Antikhippe


This worked perfectly!

If there aren't multiple elements with the same ID, you can use:

driver.execute_script('document.getElementById("ELEMENT ID").removeAttribute("readonly")')
like image 24
dataviews Avatar answered Feb 06 '23 19:02

dataviews