Selenium Webdriver NoAlertPresentException: no alert open


/ / Click to save
driver.findElement (By.xpath ("/ / * [@ id=" btn-submit "]")). Click ();
) and then there is a pop-up box. You need to click to confirm
/ / I thought this was alter

.

Alert javascriptConfirm = driver.switchTo (). Alert ();
javascriptConfirm.accept ();

but error:
Exception in thread "main" org.openqa.selenium.NoAlertPresentException: no alert open


as soon as I asked the question, I solved it by myself. It was really embarrassing.
sleep was ready in 2 seconds.
executed too fast. Before alter came out, selenium went to execute

.
Menu