code: public static ExpectedCondition<Boolean> textToBePresentInElement(final WebElement element,
                                                                      final String text) {
  
      return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
          try {
            String elementText = element.getText();
            return elementText.contains(text);
          } catch (StaleElementReferenceException e) {
            return null;
          }
        }
  
        @Override
        public String toString() {
          return String.format("text ('%s') to be present in element %s", text, element);
        }
      };
    }
docs: An expectation for checking if the given text is present in the specified element.
  
  @param element the WebElement
  @param text    to be present in the element
  @return true once the element contains the given text