I want to determine if a warning has appeared or not. I am currently using the following code:
try { Alert alert = webDriver.switchTo().alert(); // check if alert exists // TODO find better way alert.getText(); // alert handling log().info("Alert detected: {}" + alert.getText()); alert.accept(); } catch (Exception e) { }
The problem is that if there is no warning in the current state of the web page, it waits a certain amount of time before the timeout is reached, and then throws an exception, and therefore the performance is very poor.
Is there a better way, possibly an alert handler, that I can use for dynamically generated alerts?
java selenium-webdriver popup alert
Alp Nov 23. 2018-11-11T00: 00Z
source share