3

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?

2 Answers 2

7

Try using .execute_script:

date_element = driver.find_element_by_name('tb_date')
driver.execute_script("arguments[0].value = '2020-07-01';", date_element)
Sign up to request clarification or add additional context in comments.

Comments

5

You can clear and then sendkeys to that field.

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

3 Comments

Excellent answer. It works well.
Any idea how to control the input format for the date input when using different time zones regions on your OS
@Jordan could you pls explain more about your question with screenshot ? or ask new question and send url here

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.