package Techniques_to_automate_web_Element;

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.support.ui.Select;

import java.util.ArrayList;
import java.util.List;
public class WebElementAutomation {
    public static void main(String[] args) throws InterruptedException {
        WebDriver obj = new FirefoxDriver();
        // for maximizing the window.
        obj.manage().window().maximize();
        obj.get("https://rahulshettyacademy.com/dropdownsPractise/");


        //------------------------------------> Static DropDown <--------------------------------------------------

        WebElement object = obj.findElement(By.cssSelector("select#ctl00_mainContent_DropDownListCurrency"));

        Select ob = new Select(object);

        ob.selectByIndex(1);
        ob.selectByValue("AED");

        //------------------------------------> updated Static DropDown <-------------------------------------------

        Thread.sleep(2000);
        obj.findElement(By.cssSelector("div#divpaxinfo")).click();

        for(int i=1;i<=2;i++)
        {
            obj.findElement(By.cssSelector("span#hrefIncAdt")).click();
        }

        Thread.sleep(2000);
        for(int i=1;i<=3;i++)
        {
            obj.findElement(By.cssSelector("span#hrefIncChd")).click();
        }

        obj.findElement(By.cssSelector("span#hrefDecChd")).click();

        Thread.sleep(2000);
        for(int i=1;i<=2;i++)
        {
            obj.findElement(By.cssSelector("span#hrefIncInf")).click();
        }

        Thread.sleep(2000);
        obj.findElement(By.id("btnclosepaxoption")).click();

        //----------------------------> Dynamic DropDown <----------------------------------------------------------

        obj.findElement(By.cssSelector("input#ctl00_mainContent_ddl_originStation1_CTXT")).click();

        obj.findElement(By.xpath("//a[@text='Bengaluru (BLR)']")).click();
        Thread.sleep(2000);//to hold or pause your test

        obj.findElement(By.xpath("(//a[@text='Chennai (MAA)'])[2]")).click(); // usually use that kind of xpath when full path also give similar value.


        //---------------------------------> Auto suggestive Dropdown <----------------------------------------------

        obj.findElement(By.id("autosuggest")).sendKeys("ind");

        Thread.sleep(3000);

        List<WebElement> obj2 = obj.findElements(By.cssSelector("li[class='ui-menu-item'] a"));


        for(WebElement objects: obj2)
        {
             if(objects.getText().equalsIgnoreCase("India"))
             {
                   objects.click();
             }
        }

    }
}
