1

In a table element I have the following for a date picker:

<input name="tb_date" type="text" value="2020-07-15" onchange="javascript:setTimeout('__doPostBack(\'tb_date\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="tb_date" class="align-center" style="font-size:14pt;width:120px;">

I can get the input element as follows:

date_element = driver.find_element_by_name('tb_date')

That is fine. But when I try to change the value on this element, it seems to append to the current value.

date_element.send_keys('2020-07-01')
date_element.click()

So the datepicker has a value of '2020-07-152020-07-01'

How can I delete the value attribute and input a new one?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
arsenal88
  • 1,040
  • 2
  • 15
  • 32

2 Answers2

5

Try using .execute_script:

date_element = driver.find_element_by_name('tb_date')
driver.execute_script("arguments[0].value = '2020-07-01';", date_element)
frianH
  • 7,295
  • 6
  • 20
  • 45
3

You can clear and then sendkeys to that field.

date_element.clear();
date_element.send_keys('2020-07-01')
date_element.click();
Justin Lambert
  • 940
  • 1
  • 7
  • 13