Calendar Date Picker Handle using Selenium :
- Calendar Date Picker is just a like a table with set of rows and columns with numbers.
- To select a date from calendar we just have to navigate to the cell where our desired date is present and perform operation on cell.
- We always see some input boxes, where we need to pick dates from the calendar / Date picker widget.
- When we click on that input box, a calendar / Date picker widget is open and we have to choose the appropriate date value from that widget.
- I am using the findElements method to search all the dates.
- I will receive the text and click on the Expected date.
- Sometimes Calendar / Date picker code within iFrame so, that time we have need to handle iFrame.
- First switchTo iFrame then handle Cell data using tr (Table row) and td (Table Data).
Scenarios :
- Launch Browser.
- Open URL.
- If Calendar / Date Picker into iFrame then switchTo into iFrame.
- Identify table using ID where we want to click on calendar / Date picker.
- Read all tr (Table row) and td (Table Data).
- Read each and every cell record.
- Compare / Verify every Actual cell (Date) record with Expected cell (Date).
- If found Expected cell (Date) within table then click on that Cell (Date).
Example : Calendar Date Picker Handle using Selenium:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class DatePicker { WebDriver driver; @BeforeTest public void start(){ System.setProperty("webdriver.firefox.bin", "C:\\ firefox.exe"); driver = new FirefoxDriver(); } @Test public void Test(){ driver.get("http://jqueryui.com/datepicker/"); driver.switchTo().frame(0); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); //Click on textbox so that datepicker will come driver.findElement(By.id("datepicker")).click(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); //Click on next so that we will be in next month driver.findElement(By.xpath(".//*[@id='ui-datepicker-div']/div/a[2]/span")).click(); WebElement dateWidget = driver.findElement(By.id("ui-datepicker-div")); List rows=dateWidget.findElements(By.tagName("tr")); List columns=dateWidget.findElements(By.tagName("td")); for (WebElement cell: columns){ //Select 10th Date if (cell.getText().equals("10")){ cell.findElement(By.linkText("10")).click(); break; } } } } |
How to Select Date from DatePicker/Calendar in Selenium Webdriver and How to Select a Date From DatePicker Using Selenium and Handle Date Time Picker Control Using Selenium Webdriver and How to handle calendar in Selenium Webdriver or Web table and How To Handle Different Types Of Calendars In Selenium