I managed to write this code:
Wait wait = new FluentWait<>(driver).withTimeout(30, TimeUnit.SECONDS);
try{
wait.until((AppiumFunction<Appium, Alert>) input -> input.getDriver().switchTo().alert()).accept();
}catch(Exception e){…
… but this seems to work only if alert is already displayed by the time this function is being called. If it is called sooner, Exception is thrown… Even though 30 seconds is put as parameter in ‘withTimeout’, exception is throw sooner.
Any better approach to this? It doesn’t need to be Alert, it could go for any WebElement.
Some reference: