When I open a page, an alert is being displayed. I tried to accept it using the below code.
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.ultimateqa.com/fake-landing-page/");
driver.switchTo().alert().accept();
It's not working and got NoAlertPresentException. Then I tried to wait for the alert with the below code.
WebDriverWait wait= new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.accept();
It is still not working and got timeoutException now.