java.lang.Object
net.serenitybdd.screenplay.playwright.Target

public class Target extends Object
Locate an element on the page using a Playwright selector. Playwright selectors can use text, css, xpath, role selectors, and more.

Supports:

  • Parameterized selectors: Target.the("item {0}").locatedBy("[data-id='{0}']").of("123")
  • Nested targets: button.inside(form)
  • Chained locators: form.find(button)
  • Frame support: Target.the("editor").inFrame("#iframe").locatedBy("#content")
See Also:
  • Constructor Details

    • Target

      public Target(String label, String selector)
      Create a new Target with label and selector.
    • Target

      protected Target(String label, String selector, List<String> framePath, Target container)
      Create a new Target with all properties.
  • Method Details

    • the

      public static Target.TargetBuilder the(String label)
      Start building a Target with a descriptive label.
      Parameters:
      label - Human-readable description of the element
      Returns:
      A TargetBuilder to continue configuration
    • of

      public Target of(String... parameters)
      Create a parameterized version of this target by substituting placeholders. Placeholders use the format {0}, {1}, etc.

      Example:

       Target ITEM = Target.the("item {0}").locatedBy("[data-id='{0}']");
       Target item123 = ITEM.of("123"); // selector becomes "[data-id='123']"
       
      Parameters:
      parameters - Values to substitute for {0}, {1}, etc.
      Returns:
      A new Target with substituted values (original is unchanged)
    • inside

      public Target inside(Target containerTarget)
      Create a target that locates this element inside a container element. Uses Playwright's locator chaining: container.locator(this)

      Example:

       Target BUTTON = Target.the("submit button").locatedBy("button[type='submit']");
       Target FORM = Target.the("login form").locatedBy("#login-form");
       Target submitInForm = BUTTON.inside(FORM);
       
      Parameters:
      containerTarget - The container element
      Returns:
      A new Target that searches within the container
    • find

      public Target find(Target childTarget)
      Create a target that chains this locator with a child locator. Uses Playwright's locator chaining: this.locator(child)

      Example:

       Target FORM = Target.the("login form").locatedBy("#login-form");
       Target BUTTON = Target.the("submit button").locatedBy("button[type='submit']");
       Target formButton = FORM.find(BUTTON);
       
      Parameters:
      childTarget - The child element to find within this target
      Returns:
      A new Target with chained selectors
    • inFrame

      public Target inFrame(String frameSelector)
      Specify that this target is inside an iframe. Can be called multiple times for nested frames.
      Parameters:
      frameSelector - Selector for the iframe element
      Returns:
      A new Target with the frame path
    • asSelector

      public String asSelector()
      Get the raw selector string.
      Returns:
      The Playwright selector
    • isInFrame

      public boolean isInFrame()
      Check if this target is inside an iframe.
      Returns:
      true if the target requires frame navigation
    • getFramePath

      public List<String> getFramePath()
      Get the frame path for this target.
      Returns:
      List of frame selectors (empty if not in a frame)
    • resolveFor

      public com.microsoft.playwright.Locator resolveFor(com.microsoft.playwright.Page page)
      Resolve this target to a Playwright Locator.
      Parameters:
      page - The Playwright Page
      Returns:
      A Locator for this target
    • getContainer

      public Target getContainer()
      Get the container target (if any).
      Returns:
      The container target, or null if not nested
    • toString

      public String toString()
      Overrides:
      toString in class Object