3

My application HTML5 date picker is used.

We need to select the date from that date picker, but the date picker doesn't have any web element in the DOM.

Due to that, we are unable to select the date.

How can I solve this problem?

<form action="/action_page.php">
    Date:
    <br>
    <input type="date" name="date">
    <br>

    <input type="submit">
</form>

this is our html 5 date picker code.

3
  • Hi, could you add some code that you've tried? It will help us better understand the issue. Commented Sep 27, 2018 at 13:22
  • Possible duplicate of How to select the Date Picker In Selenium WebDriver Commented Sep 27, 2018 at 16:46
  • Try with sendkeys. If your date picker has a text box attached with it to display the selected date Commented Sep 27, 2018 at 18:57

1 Answer 1

3

There will be many approaches but suggesting sendKeys approach.

If we see the DOM of the Date Picker control, there is only input box for date. To handle this type of control first fill date with string, i.e. if date format is MM/dd/yyyy, then pass 09282018 to the input box. Note, this will be depends on your date format.

WebElement date = driver.findElement(By.xpath("//form//input[@name='date']"));
//Fill date as format, ie, MM/dd/yyyy
date.sendKeys("09282018");
date.submit();
Sign up to request clarification or add additional context in comments.

3 Comments

in general we will do like this. but thing is that input box is non editable, read only. so i can't send the date using sendKeys(). so how to handle this type of date pickers?
Read only means you are not able to enter string and any how you need to select date using UI? Is that the case? Because as per DOM this should work.
@SanjayBhimini Could you Please share the other approaches for the same

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.