code: public static ExpectedCondition<Boolean> textToBe(final By locator, final String value) {
      return new ExpectedCondition<Boolean>() {
        private String currentValue = null;
  
        @Override
        public Boolean apply(WebDriver driver) {
          try {
            currentValue = driver.findElement(locator).getText();
            return currentValue.equals(value);
          } catch (Exception e) {
            return false;
          }
        }
  
        @Override
        public String toString() {
          return String.format("element found by %s to have text \"%s\". Current text: \"%s\"",
                               locator, value, currentValue);
        }
      };
    }
docs: An expectation for checking WebElement with given locator has specific text
  
  @param locator used to find the element
  @param value   used as expected text
  @return Boolean true when element has text value equal to @value