code: public static ExpectedCondition<Boolean> elementSelectionStateToBe(final WebElement element,
                                                                       final boolean selected) {
      return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
          return element.isSelected() == selected;
        }
  
        @Override
        public String toString() {
          return String.format("element (%s) to %sbe selected", element, (selected ? "" : "not "));
        }
      };
    }
docs: An expectation for checking if the given element is selected.
  
  @param element  WebElement to be selected
  @param selected boolean state of the selection state of the element
  @return true once the element's selection stated is that of selected