0% found this document useful (0 votes)
4 views3 pages

Challenges of Datepicker

The document contains Java test classes for date picker functionality on various airline and hotel booking websites, specifically Turkish Airlines, FlyDubai, and Trivago. Each test navigates to the respective website, interacts with the date picker elements, and selects specific dates while handling WebDriver's bot detection. The tests utilize Selenium for web automation and include wait conditions to ensure elements are visible before interacting with them.

Uploaded by

Sarithag Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Challenges of Datepicker

The document contains Java test classes for date picker functionality on various airline and hotel booking websites, specifically Turkish Airlines, FlyDubai, and Trivago. Each test navigates to the respective website, interacts with the date picker elements, and selects specific dates while handling WebDriver's bot detection. The tests utilize Selenium for web automation and include wait conditions to ensure elements are visible before interacting with them.

Uploaded by

Sarithag Devi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

List;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class DatePickerTestsTurkishAirlines extends BaseTest {
@Test
@SneakyThrows
public void turkishAirlinesDatePicker() {
//Because of the Webdriver Bot Detection this test cannot be run properly.
//But you can follow the approach in debug mode I run the test successfully and it worked.
driver.navigate().to("https://www.turkishairlines.com");
//Click and open the Date Picker
driver.findElement(By.id("dateSelector")).click();
//This is from date picker table
WebElement dateWidgetFrom = wait.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className("ui-datepicker-
calendar"))).get(0);
//This are the columns of the from date picker table
List<WebElement> columns = dateWidgetFrom.findElements(By.tagName("td"));
DateUtil.clickGivenDay(columns, DateUtil.getCurrentDay());
//Wait a bit to see that we have selected the data properly.
Thread.sleep(5000);
}
}

/////////////////////////////////////////////////////////////////////////////////////////////
public class DatePickerTestsFlyDubai extends BaseTest {
@Test
@SneakyThrows
public void flyDubaiDatePicker() {
//Go to website
driver.get("https://www.flydubai.com/en/");
//Click Departure Place
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".airportPickerTo.
makeBookingTo.mat-form-group"))).click();
//Wait Dropdown and click the first city
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector(" .makeBookingTo .search-list-dropdown [data-metro-active='false']:nth-of-
type(1)"))).click();
//Wait the DatePicker Opens
wait.until(ExpectedConditions.visibilityOfElementLocated((By.cssSelector(".lightpick__inner"
))));
//This are the cell of the from date picker table for departure. Get all elements.
List<WebElement> cellsOfDepartureDate = wait.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("section:nth-of-
type(1) > .lightpick__days > div")));
//Click the today for Departure
DateUtil.clickGivenDay(cellsOfDepartureDate, DateUtil.getCurrentDay());
//This are the cell of the from date picker table for arrival. Get all elements.
List<WebElement> cellsOfArrivalDate = wait.until(
ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("section:nth-of-
type(2) > .lightpick__days > div")));
//Click the 4th day (element).
cellsOfArrivalDate.get(4).click();
//Wait and see the selection.
Thread.sleep(5000);
}
}

//////////////////////////////////////////////////////////////////////
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class DatePickerTestTrivago extends BaseTest {
@Test
@SneakyThrows
public void trivagoDatePickerTest() {
//Go to Trivago.com
driver.navigate().to("https://www.trivago.com.tr/");
//Search a Hotel
WebElement searchText =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("querytext")));
searchText.clear();
searchText.sendKeys("Antalya");
//Wait and Click the First Results
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".ssg-
suggestions>li:nth-of-type(1)"))).click();
//Wait for Visibility of Calendar / DatePicker
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".two-month-
calendar")));
//Select Start Date (Wait visibility then click the start date.)
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector(
".cal-day.cal-is-weekend.cal-is-selectable.cal-is-range.cal-is-range-start,.cal-day.cal-is-
selectable.cal-is-range.cal-is-range-start"))).click();
//Select End Date (Wait Visibility then click the end date)
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector(
".cal-day.cal-is-weekend.cal-is-selectable.cal-is-range.cal-is-range-end,.cal-day.cal-is-
selectable.cal-is-range.cal-is-range-end"))).click();
//See the results with your eyes. :)
//From now on, you can do what you want.
Thread.sleep(4000);
}
}

You might also like