package Handling_SSL_Certification_and_AJAXCalls;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class AjaxCall {
    public static void main(String[] args) {

      //---------------> here i am creating an object of firefox browser.
        WebDriver obj = new FirefoxDriver();

        //---------------------> Defining the Explicit time.
        WebDriverWait wait = new WebDriverWait(obj, Duration.ofSeconds(5));

        //-------> Fetch the link and open the web on browser of which object is created.
        obj.get("http://omayo.blogspot.com/");



        // creating javaScript Executor.

        JavascriptExecutor js = (JavascriptExecutor)obj;

        js.executeScript("window.scrollBy(0,1400)"); // for scroll web downwards.

        js.executeScript("window.scrollBy(60,0)"); // for scroll web right side.

        //---------------------------------------> (Finding the Locator of Dropdown Button) <-----------------------------------

        //---> creating a button and storing a locator for maintainability of code.
        WebElement DropdownButton = obj.findElement(By.cssSelector("button.dropbtn"));



        DropdownButton.click();

        WebElement FlipkartButton = obj.findElement(By.xpath("//div[@id='myDropdown']/a[2]"));

        //--------------------------------------> Adding Explicit wait to handle ajax call.

        wait.until(ExpectedConditions.visibilityOf(FlipkartButton));
        FlipkartButton.click();





    }
}
