If you're looking to ensure visibility of an element globally, consider implementing a method and utilizing it throughout your code. Here's an example:
public static boolean ElementVisible(By element, WebDriver driver) {
// Set maximum attempts and sleep time
int maxAttempts = 2;
long sleepTimeInMillisForEachIteration = 500;
for (int counter = 0; counter <= maxAttempts; counter++) {
try {
driver.findElement(element);
return true;
} catch (NoSuchElementException | ElementNotVisibleException e) {
if (counter == maxAttempts) {
return false;
}
try {
Thread.sleep(sleepTimeInMillisForEachIteration);
continue;
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
return false;
}
This method will interact with the element if it is visible, handling exceptions and returning false otherwise.