Thursday 7 May 2015

Calender handling in "makemytrip.com"..

package Assignments;


import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class MakeMyTrip {

public static void main(String[] args) throws InterruptedException {
java.util.Scanner scn = new java.util.Scanner(System.in);
System.out.println("Enter the date");
int date = scn.nextInt();

System.out.println("Enter the month");
String month = scn.next();

System.out.println("Enter return date");
int date1 = scn.nextInt();

System.out.println("Enter return month");
String month1 = scn.next();


WebDriver driver = new FirefoxDriver();
driver.get("http://www.makemytrip.com/");
int count = 0, count1 =0;
Actions act = new Actions(driver);

WebElement fromele = driver.findElement(By.id("from_typeahead1"));
fromele.click();
fromele.sendKeys("ban");
act.sendKeys(Keys.ENTER);

driver.findElement(By.id("to_typeahead1")).sendKeys("hyd");
act.sendKeys(Keys.ENTER);

Thread.sleep(2000);

driver.findElement(By.xpath("//span[text()='DEPARTURE']")).click();

String datePicker = "//div[div[div[span[text()='"+month+"']]]]//a[text()='"+date+"']";

while(count<=12)
{
try
{
driver.findElement(By.xpath(datePicker)).click();
break;
}
catch(Exception e)
{
driver.findElement(By.xpath("//a[@title='Next']")).click();
Thread.sleep(2000);
count++;
}

}

driver.findElement(By.xpath("//span[text()='RETURN']")).click();

String retdatePicker = "//div[div[div[span[text()='"+month1+"']]]]//a[text()='"+date1+"']";

while(count1<=12)
{
try
{
driver.findElement(By.xpath(retdatePicker)).click();
break;
}
catch(Exception e)
{
driver.findElement(By.xpath("//span[text()='Next']")).click();
Thread.sleep(2000);
count1++;
}

}


}

}

1 comment: