Class ElementConditions

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static <T extends Component> Predicate<T> containsText(String text) Checks if text content of the component contains the given text.
      static <T extends Component> Predicate<T> containsText(String text, boolean ignoreCase) Checks if text content of the component contains the given text.
      static <T extends Component> Predicate<T> hasAttribute(String attribute) Checks if the given attribute has been set on the component.
      static <T extends Component> Predicate<T> hasAttribute(String attribute, String value) Checks if the given attribute has been set on the component and has exactly the given value.
      static <T extends Component> Predicate<T> hasNotAttribute(String attribute) Checks if the given attribute has not been set on the component.
      static <T extends Component> Predicate<T> hasNotAttribute(String attribute, String value) Checks if the given attribute has been set on the component or has a value different from given one.
      static <T extends Component> Predicate<T> hasLabel(String label) Checks if the component is labelled by exactly the given text.
      static <T extends Component> Predicate<T> labelContains(String text) Checks if the component's label contains the given text.
      static <T extends Component> Predicate<T> placeholderContains(String text) Checks if the component's placeholder contains the given text.
      static <T extends Component> Predicate<T> hasAriaLabel(String ariaLabel) Checks if the component identifies itself to assistive technology via the given aria-label.
      static <T extends Component> Predicate<T> ariaLabelContains(String text) Checks if the component's aria-label contains the given text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • containsText

         static <T extends Component> Predicate<T> containsText(String text)

        Checks if text content of the component contains the given text. Input text is compared with value obtained either by getText, getText if element is a text node, or the normalized version of getInnerHtml. In all other cases getTextRecursively is used, but in this case text from nested elements is concatenated without space separators. The comparison is case-sensitive. For Html components the innerHTML tags are stripped and whitespace is normalized and trimmed. For example, given HTML

        the text that will be checked will be Hello there now!.
        Parameters:
        text - the text the component is expected to have as its content.
        Returns:

        this element query instance for chaining

      • containsText

         static <T extends Component> Predicate<T> containsText(String text, boolean ignoreCase)

        Checks if text content of the component contains the given text. Input text is compared with value obtained either by getText, getText if element is a text node, or getInnerHtml. In all other cases getTextRecursively is used, but in this case text from nested elements is concatenated without space separators. For Html components the innerHTML tags are stripped and whitespace is normalized and trimmed. For example, given HTML

        the text that will be checked will be Hello there now!.
        Parameters:
        text - the text the component is expected to have as its content.
        ignoreCase - flag to indicate if comparison must be case-insensitive.
        Returns:

        this element query instance for chaining

      • hasAttribute

         static <T extends Component> Predicate<T> hasAttribute(String attribute)

        Checks if the given attribute has been set on the component. Attribute names are considered case-insensitive and all names will be converted to lower case automatically.

        Parameters:
        attribute - the name of the attribute, not null
        Returns:

        true if the attribute has been set, false otherwise

      • hasAttribute

         static <T extends Component> Predicate<T> hasAttribute(String attribute, String value)

        Checks if the given attribute has been set on the component and has exactly the given value. Attribute names are considered case-insensitive and all names will be converted to lower case automatically.

        Parameters:
        attribute - the name of the attribute, not null
        value - expected value, not null
        Returns:

        true if the attribute has been set, false otherwise

      • hasNotAttribute

         static <T extends Component> Predicate<T> hasNotAttribute(String attribute)

        Checks if the given attribute has not been set on the component. Attribute names are considered case-insensitive and all names will be converted to lower case automatically.

        Parameters:
        attribute - the name of the attribute, not null
        Returns:

        true if the attribute has not been set, false otherwise

      • hasNotAttribute

         static <T extends Component> Predicate<T> hasNotAttribute(String attribute, String value)

        Checks if the given attribute has been set on the component or has a value different from given one. Attribute names are considered case-insensitive and all names will be converted to lower case automatically.

        Parameters:
        attribute - the name of the attribute, not null
        value - value expected not to be set on attribute, not null
        Returns:

        true if the attribute is not set or has a value different from given one, false otherwise

      • hasLabel

         static <T extends Component> Predicate<T> hasLabel(String label)

        Checks if the component is labelled by exactly the given text. A component is considered labelled by a text when either:

        • its label property (read by getLabel) equals the text, or
        • some <label for="componentId"> element elsewhere in the UI has that text as its (recursive) content.
        The second form covers the HTML pattern where a separate com.vaadin.flow.component.html.NativeLabel (or any <label> element) targets an input via the for attribute.
        Parameters:
        label - the expected label, not null
        Since:

        1.1

      • labelContains

         static <T extends Component> Predicate<T> labelContains(String text)

        Checks if the component's label contains the given text. The label is read in the same way as hasLabel (component's label property or a referring <label for="..."> element). Comparison is case-sensitive.

        Parameters:
        text - substring to find in the label, not null
        Since:

        1.1

      • placeholderContains

         static <T extends Component> Predicate<T> placeholderContains(String text)

        Checks if the component's placeholder contains the given text. Resolution prefers getPlaceholder — components that don't implement HasPlaceholder are never matched (they have no placeholder to test against). Comparison is case-sensitive.

        Parameters:
        text - substring to find in the placeholder, not null
        Since:

        1.1

      • hasAriaLabel

         static <T extends Component> Predicate<T> hasAriaLabel(String ariaLabel)

        Checks if the component identifies itself to assistive technology via the given aria-label. Useful for components like Button that don't expose a label property and for field components (e.g. TextField, TextArea) that surface their accessible name via setAriaLabel.

        Resolution prefers getAriaLabel when the component implements it, because field components back the accessible name with a property (the web component reflects it to the inner input's aria-label on the client). Otherwise falls back to reading the server-side element's aria-label attribute.

        Parameters:
        ariaLabel - the expected aria-label, not null
        Since:

        1.1

      • ariaLabelContains

         static <T extends Component> Predicate<T> ariaLabelContains(String text)

        Checks if the component's aria-label contains the given text. Comparison is case-sensitive. Resolution follows the same rules as hasAriaLabel — prefer getAriaLabel over the raw element attribute so that field components are matched.

        Parameters:
        text - substring to find in the aria-label, not null
        Since:

        1.1