code: public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) {
      return new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
          try {
            return elementIfVisible(driver.findElement(locator));
          } catch (StaleElementReferenceException e) {
            return null;
          }
        }
  
        @Override
        public String toString() {
          return "visibility of element located by " + locator;
        }
      };
    }
docs: An expectation for checking that an element is present on the DOM of a page and visible.
  Visibility means that the element is not only displayed but also has a height and width that is
  greater than 0.
  
  @param locator used to find the element
  @return the WebElement once it is located and visible