Class Target
java.lang.Object
net.serenitybdd.screenplay.playwright.Target
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating Target instances. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the raw selector string.Create a target that chains this locator with a child locator.Get the container target (if any).Get the frame path for this target.Specify that this target is inside an iframe.Create a target that locates this element inside a container element.booleanCheck if this target is inside an iframe.Create a parameterized version of this target by substituting placeholders.com.microsoft.playwright.LocatorresolveFor(com.microsoft.playwright.Page page) Resolve this target to a Playwright Locator.static Target.TargetBuilderStart building a Target with a descriptive label.toString()
-
Constructor Details
-
Target
Create a new Target with label and selector. -
Target
Create a new Target with all properties.
-
-
Method Details
-
the
Start building a Target with a descriptive label.- Parameters:
label- Human-readable description of the element- Returns:
- A TargetBuilder to continue configuration
-
of
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
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
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
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
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
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
Get the container target (if any).- Returns:
- The container target, or null if not nested
-
toString
-