package zacksolutions;

import java.time.Duration;

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.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * Ajax
 */
public class Ajax {

  public static WebDriver driver;
  public static String hoverText;

  public static void main(String[] args) throws InterruptedException {

    Initialize();
  }

  public static void Initialize() throws InterruptedException {
    System.setProperty("web-driver.gecko.driver", "user.dir" + "LearnSelenium/DemoProject/drivers/geckodriver");
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
    String url = "https://www.amazon.com/";
    driver.get(url);
    try {
      Actionz();
    } finally {
      driver.close();
    }
  }

  public static void Actionz() {
    Actions actions = new Actions(driver);
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nav-link-accountList")));
    WebElement hover = driver.findElement(By.cssSelector("#nav-link-accountList"));
    actions.moveToElement(hover);
    hoverText = driver.findElement(By.cssSelector(".sc-ktJbId.bSNqcv")).getText();
    System.out.println(hoverText);
  }
}
