0

When I want to send_keys to a readonly datepicker, I failed to input the date. Here is thelink I try to remove the readonly first, clear, and send_keys.

url="https://epaper.oeeee.com/epaper/A/html/2018-02/06/node_2637.htm"
driver.get(url)
d=driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/input")
driver.execute_script('arguments[0].removeAttribute(\"readonly\")', d)
driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/input').clear()
d.send_keys('2018-02-02')
d.send_keys(Keys.RETURN)

date badget image

Could anyone tell me why?

Many thanks

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Joan Mok
  • 91
  • 3
  • 9
  • clear() does not work at all on some kinds of fields. did you try doing element.send_keys(Keys.CONTROL + 'a') element.send_keys(Keys.BACKSPACE) –  Dec 17 '20 at 14:01

2 Answers2

0

First of all: I don't think it's read-only, I can regularely click on it, without changing anything. then I don't think that you can clear and set it again as you might want. But there are quite a few solved datepicker problems, I will link you some with their respective solutions below:

How to change the date of a hidden element of a Datepicker using setAttribute method and Selenium with Python?
Selenium calendar picker: I can click manually but Selenium cant click
How do I click on active day on date picker using selenium python?

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
Timeler
  • 377
  • 1
  • 11
0

jQuery Datepicker

The jQuery Datepicker is tied to a standard form <input> field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.

If you observe the HTML DOM of the web application it uses jQuery

"jquery": "/epaper/js/lib/jquery/jquery/1.10.1/jquery.js"

Now as per the HTML of the WebElement:

<input type="text" class="datepicker" readonly="readonly" data-date="2018-02-04">

Though the datepicker field is an <input> field, on click it calls the jQuery based datepicker class which doesn't accept any text input. Hence send_keys() fails to send any character sequence to the <input> field.

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