Dealing with an alert that does not always display can be tricky. For example, I have encountered a situation where I am logged into the system using credentials: eee / eee_123. If another user is already logged in before me, an alert pops up asking if I want to kick them out. However, if there are no other active users with the same credentials, I want to log in smoothly without any alerts.
My question is: how do I effectively handle this alert? I have tried using the following condition:
if (ExpectedConditions.alertIsPresent() != null) {
driver.switchTo().alert().accept();
}
But unfortunately, it's not yielding the desired results.