Select a date in a DatePicker with Selenium WebDriver
How to use Selenium WebDriver to select a date in a date picker
Many modern websites use date pickers to select dates. This article will show you how to use Selenium WebDriver to select a date via a date picker in an automated test script. I will script using raw Selenium WebDriver in RSpec, using TestWise IDE.
Test Case 1: Select tomorrow’s date (Simple)
Test Page URL: https://fengyuanchen.github.io/datepicker/
Following a typical test design, do it manually first to come up with a test design.
- Click the text control to show the date picker
- Select tomorrow’s date
- Close the date picker, if not auto-closed after the selection
- Verify the selected date
Then implement the above in an automated test script.
From experience, picking a date involves date calculation, such as tomorrow and next week’s date. ActiveSupport (part of Rails) is very helpful on that.
Date.today.advance(:days => 1) # tomorrow
# even better
Also, formatting a date.
Date.today.strftime("%m/%d/%Y") #=> 12/17/2022 if today is 2022-12-17