2024-02-13 22:19:38
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.testng.annotations.Test;
 
public class lowest_Flight_16 {
    WebDriver dr;
    boolean found = false;
 
    public lowest_Flight_16() {
        // Set the path to the Firefox binary explicitly
        System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\geckodriver.exe");
 
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
 
        dr = new FirefoxDriver(firefoxOptions);
        dr.manage().window().maximize();
        dr.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    }
 
    @Test
    public void newTest() throws InterruptedException {
        dr.get("https://flights.makemytrip.com/makemytrip/search/O/O/E/1/0/0/S/V0/BOM_DEL_30-08-2017");
 
        List<WebElement> price = dr.findElements(By.xpath("//*[@id='content']/div/div[5]/div[5]/div[2]/div/div[2]/div[2]/div[6]/p[1]/span[2]"));
        System.out.println(price.size());
 
        ArrayList<Integer> prices = new ArrayList<Integer>();
        for (int i = 0; i < price.size(); i++) {
            Integer priceInt = Integer.valueOf(price.get(i).getText().replace(",", ""));
            prices.add(priceInt);
        }
        Integer minPrice = Collections.min(prices);
        System.out.println("Min Price is " + minPrice);
 
        List<WebElement> allBookbtn = dr.findElements(By.xpath("//*[@id='content']/div/div[5]/div[5]/div[2]/div/div[2]/div[2]/div[7]/p/a"));
        Thread.sleep(3000);
        for (int i = 0; i < price.size(); i++) {
            Integer priceInt1 = Integer.valueOf(price.get(i).getText().replace(",", ""));
            System.out.println(priceInt1);
            if (priceInt1 == minPrice) {
                allBookbtn.get(i).click();
                break;
            }
        }
    }
 
    public static void main(String[] args) {
        lowest_Flight_16 lowestFlightTest = new lowest_Flight_16();
        try {
            lowestFlightTest.newTest();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            // Close the browser after execution
            lowestFlightTest.dr.quit();
        }
    }
}
 
Invalid Email or Password