How To Handle Calendar Pop Up In Selenium WebDriver

Calendar Pop Up is a type of Hidden Division Pop up. Since this pop up is a part of html page we can use findElements() method and handle it.

In the web page sometimes you’ll fail to inspect a particular element, in that time, go to firebug window in the firebug toolbar and select the firbug search symbol.

Here is an example which shows how to handle calendar pop up :

1) Launch Eclipse, create a project, a package, and a class under named “test1.java”.

2) Navigate to site “http://www.makemytrip.com/”. For this you need to add the following lines of code in your script :
WebDriver driver=new FirefoxDriver();
driver.get(“http://www.makemytrip.com/”);

a

3) Right click on the calendar option given for Departure and inspect it. Chose the date of departure as 3rd March. To do this much you need to include the following lines of code in your script :

driver.findElement(By.id(“start_date_sec”)).click();
driver.findElement(By.xpath(“//*[@id=’ui-datepicker-div’]/div[3]/table/tbody/tr[1]/td[3]/a”)).click();

b

4) Now again click on the Departure Calendar and click on the Cross button(X) to close the calendar. For this, first locate the calendar and then click on it.

driver.findElement(By.id(“start_date_sec”)).click();
driver.findElement(By.xpath(“//*[@id=’ui-datepicker-div’]/div[5]/button[2]”)).click();

c

This is all about calendar pop up. Handling Calendar pop up is not complex. All you have to do is locate the element and locate it correctly, then perform action…!!!

Add Comment