Yatra Search

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Sure, here's a sample Selenium Java program that performs the actions you

described:

```java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

import java.util.concurrent.TimeUnit;

public class YatraFlightSearch {


public static void main(String[] args) {

// Set the webdriver path and start Chrome browser


System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();

// Set implicit wait for 10 seconds


driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Navigate to Yatra.com
driver.get("https://www.yatra.com/");

// Enter data in Depart from field and select Bangalore


WebElement departFrom = driver.findElement(By.id("BE_flight_origin_city"));
departFrom.sendKeys("Ban");
WebElement bangaloreOption =
driver.findElement(By.xpath("//p[contains(text(), 'Bangalore')]"));
bangaloreOption.click();

// Enter data in Going to field and select Chennai


WebElement goingTo = driver.findElement(By.id("BE_flight_arrival_city"));
goingTo.sendKeys("Che");
WebElement chennaiOption =
driver.findElement(By.xpath("//p[contains(text(), 'Chennai')]"));
chennaiOption.click();

// Select the date


WebElement datePicker = driver.findElement(By.id("BE_flight_origin_date"));
datePicker.click();
WebElement date = driver.findElement(By.xpath("//td[@data-
handler='selectDay' and @data-month='2' and @data-year='2024']/a[text()='15']"));
date.click();

// Click on the Search Flight button using Actions


WebElement searchFlightBtn =
driver.findElement(By.xpath("//button[contains(text(), 'Search Flights')]"));
Actions actions = new Actions(driver);
actions.moveToElement(searchFlightBtn).click().perform();

// Close the browser


driver.quit();
}
}
```

Note that you'll need to download the ChromeDriver executable and replace the
"path/to/chromedriver" string with the actual path to the executable on your
machine. Also, make sure that you have the latest version of Selenium and
ChromeDriver installed.

You might also like