Datepicker
Datepicker
List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
if(browser.equals("Chrome")){
System.setProperty("webdriver.chrome.driver",
".\\chromedriver.exe");
driver = new ChromeDriver();
}
return driver;
}
// F L I G H T S
public static WebElement HomePage_Flights(WebDriver driver){
setup("Chrome");
driver.navigate().to(baseUrl);
driver.manage().window().maximize();
HomePage_Flights(driver).click();
actions.moveToElement(driver.findElement(By.id("FlightsDateStart")));
actions.click();
actions.build().perform();
// D A T E P I C K E R
//Thread.sleep(10000);
int myMonth = 5;
int myDay = 2;
int myYear = 2710;
JavascriptExecutor jsexecutor = (JavascriptExecutor)driver;
WebElement calendarTitle =
driver.findElement(By.xpath("//div[8]//nav[1]//div[2]"));
calendarTitle.click();
/*********************************************************************/
if(Integer.parseInt(currentYear.getText()) != myYear){
jsexecutor.executeScript("arguments[0].click();", currentYear);
while(!quit){
WebElement yearRange =
driver.findElement(By.xpath("//div[8]//nav[1]//div[2]"));
int yearStart =
Integer.parseInt(yearRange.getText().substring(0,4));
int yearEnd =
Integer.parseInt(yearRange.getText().substring(7));
if(Integer.parseInt(year.getAttribute("data-
year")) == myYear){
jsexecutor.executeScript("arguments[0].click();", year);
quit = true;
}
}
}else{
WebElement nextDecade =
driver.findElement(By.xpath("//div[8]//nav[1]//div[3]"));
jsexecutor.executeScript("arguments[0].click();",
nextDecade);
}
}
/*********************************************************************/
try {
WebElement currentMonth = driver.findElement(
By.xpath("//div[@class = 'datepicker--cell
datepicker--cell-month -current-']"));
if((Integer.parseInt(currentMonth.getAttribute("data-month"))+1)
> myMonth){
}else if ((Integer.parseInt(currentMonth.getAttribute("data-
month"))+1) != myMonth) {
WebElement month =
driver.findElement(By.xpath("//div[@class = 'datepicker--cell datepicker--cell-
month' and "
+ "@data-month = '" + (myMonth-1) + "']"));
jsexecutor.executeScript("arguments[0].click();", month);
}else{
jsexecutor.executeScript("arguments[0].click();",
currentMonth);
}
} catch (NoSuchElementException e) {
// TODO: handle exception
WebElement month = driver.findElement(By.xpath("//div[@class =
'datepicker--cell datepicker--cell-month' and "
+ "@data-month = '" + (myMonth-1) + "']"));
jsexecutor.executeScript("arguments[0].click();", month);
}
/*********************************************************************/
/*********************************************************************/
try {
WebElement currentDate = driver.findElement(
By.xpath("//div[8]//div[1]//div[1]//div[2]"
+ "//div[@class = 'datepicker--cell
datepicker--cell-day -current-']"));
if(Integer.parseInt(currentDate.getAttribute("data-date")) >
myDay){
}else if ((Integer.parseInt(currentDate.getAttribute("data-
date"))) != myDay) {
WebElement date =
driver.findElement(By.xpath("//div[8]//div[1]//div[1]//div[2]//div["
+ "@data-date = '" + myDay + "' "
+ "and @data-month = '" + (myMonth-
1)+ "']"));
jsexecutor.executeScript("arguments[0].click();", date);
}else{
jsexecutor.executeScript("arguments[0].click();",
currentDate);
}
} catch (NoSuchElementException e) {
// TODO: handle exception
WebElement date =
driver.findElement(By.xpath("//div[8]//div[1]//div[1]//div[2]//div["
+ "@data-date = '" + myDay + "' "
+ "and @data-month = '" + (myMonth-1)+
"']"));
jsexecutor.executeScript("arguments[0].click();", date);