java.lang.Object
net.serenitybdd.screenplay.playwright.ui.Label

public class Label extends Object
Factory for locating label elements using Playwright selectors.

Useful for finding labels associated with form fields or as standalone text elements.

Sample usage:

     Target usernameLabel = Label.withText("Username");
     Target exactLabel = Label.withExactText("Email Address");
     Target emailLabel = Label.forFieldId("email");
 
  • Method Details

    • withText

      public static Target withText(String text)
      Locate a label containing the specified text (partial match).
      Parameters:
      text - The text to search for within the label
      Returns:
      A Target for the label element
    • withExactText

      public static Target withExactText(String text)
      Locate a label with exact text content.
      Parameters:
      text - The exact text content
      Returns:
      A Target for the label element
    • forFieldId

      public static Target forFieldId(String fieldId)
      Locate a label by its 'for' attribute (field association).
      Parameters:
      fieldId - The id of the associated form field
      Returns:
      A Target for the label element
    • locatedBy

      public static Target locatedBy(String selector)
      Locate a label using a custom Playwright selector.
      Parameters:
      selector - A valid Playwright selector
      Returns:
      A Target for the label element