Class FrameLocatorImpl
- java.lang.Object
-
- com.microsoft.playwright.impl.FrameLocatorImpl
-
- All Implemented Interfaces:
FrameLocator
class FrameLocatorImpl extends java.lang.Object implements FrameLocator
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.microsoft.playwright.FrameLocator
FrameLocator.GetByAltTextOptions, FrameLocator.GetByLabelOptions, FrameLocator.GetByPlaceholderOptions, FrameLocator.GetByRoleOptions, FrameLocator.GetByTextOptions, FrameLocator.GetByTitleOptions, FrameLocator.LocatorOptions
-
-
Field Summary
Fields Modifier and Type Field Description private FrameImplframeprivate java.lang.StringframeSelector
-
Constructor Summary
Constructors Constructor Description FrameLocatorImpl(FrameImpl frame, java.lang.String selector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FrameLocatorfirst()Returns locator to the first matching frame.FrameLocatorImplframeLocator(java.lang.String selector)When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.LocatorgetByAltText(java.lang.String text, FrameLocator.GetByAltTextOptions options)Allows locating elements by their alt text.LocatorgetByAltText(java.util.regex.Pattern text, FrameLocator.GetByAltTextOptions options)Allows locating elements by their alt text.LocatorgetByLabel(java.lang.String text, FrameLocator.GetByLabelOptions options)Allows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.LocatorgetByLabel(java.util.regex.Pattern text, FrameLocator.GetByLabelOptions options)Allows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.LocatorgetByPlaceholder(java.lang.String text, FrameLocator.GetByPlaceholderOptions options)Allows locating input elements by the placeholder text.LocatorgetByPlaceholder(java.util.regex.Pattern text, FrameLocator.GetByPlaceholderOptions options)Allows locating input elements by the placeholder text.LocatorgetByRole(AriaRole role, FrameLocator.GetByRoleOptions options)LocatorgetByTestId(java.lang.String testId)Locate element by the test id.LocatorgetByTestId(java.util.regex.Pattern testId)Locate element by the test id.LocatorgetByText(java.lang.String text, FrameLocator.GetByTextOptions options)Allows locating elements that contain given text.LocatorgetByText(java.util.regex.Pattern text, FrameLocator.GetByTextOptions options)Allows locating elements that contain given text.LocatorgetByTitle(java.lang.String text, FrameLocator.GetByTitleOptions options)Allows locating elements by their title attribute.LocatorgetByTitle(java.util.regex.Pattern text, FrameLocator.GetByTitleOptions options)Allows locating elements by their title attribute.FrameLocatorlast()Returns locator to the last matching frame.Locatorlocator(Locator selectorOrLocator, FrameLocator.LocatorOptions options)The method finds an element matching the specified selector in the locator's subtree.Locatorlocator(java.lang.String selector, FrameLocator.LocatorOptions options)The method finds an element matching the specified selector in the locator's subtree.FrameLocatornth(int index)Returns locator to the n-th matching frame.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.microsoft.playwright.FrameLocator
getByAltText, getByAltText, getByLabel, getByLabel, getByPlaceholder, getByPlaceholder, getByRole, getByText, getByText, getByTitle, getByTitle, locator, locator
-
-
-
-
Field Detail
-
frame
private final FrameImpl frame
-
frameSelector
private final java.lang.String frameSelector
-
-
Constructor Detail
-
FrameLocatorImpl
FrameLocatorImpl(FrameImpl frame, java.lang.String selector)
-
-
Method Detail
-
first
public FrameLocator first()
Description copied from interface:FrameLocatorReturns locator to the first matching frame.- Specified by:
firstin interfaceFrameLocator
-
frameLocator
public FrameLocatorImpl frameLocator(java.lang.String selector)
Description copied from interface:FrameLocatorWhen working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.- Specified by:
frameLocatorin interfaceFrameLocator- Parameters:
selector- A selector to use when resolving DOM element.
-
getByAltText
public Locator getByAltText(java.lang.String text, FrameLocator.GetByAltTextOptions options)
Description copied from interface:FrameLocatorAllows locating elements by their alt text.**Usage**
For example, this method will find the image by alt text "Playwright logo":
page.getByAltText("Playwright logo").click();- Specified by:
getByAltTextin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByAltText
public Locator getByAltText(java.util.regex.Pattern text, FrameLocator.GetByAltTextOptions options)
Description copied from interface:FrameLocatorAllows locating elements by their alt text.**Usage**
For example, this method will find the image by alt text "Playwright logo":
page.getByAltText("Playwright logo").click();- Specified by:
getByAltTextin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByLabel
public Locator getByLabel(java.lang.String text, FrameLocator.GetByLabelOptions options)
Description copied from interface:FrameLocatorAllows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.**Usage**
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
page.getByLabel("Username").fill("john"); page.getByLabel("Password").fill("secret");- Specified by:
getByLabelin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByLabel
public Locator getByLabel(java.util.regex.Pattern text, FrameLocator.GetByLabelOptions options)
Description copied from interface:FrameLocatorAllows locating input elements by the text of the associated<label>oraria-labelledbyelement, or by thearia-labelattribute.**Usage**
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
page.getByLabel("Username").fill("john"); page.getByLabel("Password").fill("secret");- Specified by:
getByLabelin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByPlaceholder
public Locator getByPlaceholder(java.lang.String text, FrameLocator.GetByPlaceholderOptions options)
Description copied from interface:FrameLocatorAllows locating input elements by the placeholder text.**Usage**
For example, consider the following DOM structure.
You can fill the input after locating it by the placeholder text:
page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");- Specified by:
getByPlaceholderin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByPlaceholder
public Locator getByPlaceholder(java.util.regex.Pattern text, FrameLocator.GetByPlaceholderOptions options)
Description copied from interface:FrameLocatorAllows locating input elements by the placeholder text.**Usage**
For example, consider the following DOM structure.
You can fill the input after locating it by the placeholder text:
page.getByPlaceholder("name@example.com").fill("playwright@microsoft.com");- Specified by:
getByPlaceholderin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByRole
public Locator getByRole(AriaRole role, FrameLocator.GetByRoleOptions options)
Description copied from interface:FrameLocatorAllows locating elements by their ARIA role, ARIA attributes and accessible name.**Usage**
Consider the following DOM structure.
You can locate each element by it's implicit role:
assertThat(page .getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Sign up"))) .isVisible(); page.getByRole(AriaRole.CHECKBOX, new Page.GetByRoleOptions().setName("Subscribe")) .check(); page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName( Pattern.compile("submit", Pattern.CASE_INSENSITIVE))) .click();**Details**
Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
Many html elements have an implicitly defined role that is recognized by the role selector. You can find all the supported roles here. ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting
roleand/oraria-*attributes to default values.- Specified by:
getByRolein interfaceFrameLocator- Parameters:
role- Required aria role.
-
getByTestId
public Locator getByTestId(java.lang.String testId)
Description copied from interface:FrameLocatorLocate element by the test id.**Usage**
Consider the following DOM structure.
You can locate the element by it's test id:
page.getByTestId("directions").click();**Details**
By default, the
data-testidattribute is used as a test id. UseSelectors.setTestIdAttribute()to configure a different test id attribute if necessary.- Specified by:
getByTestIdin interfaceFrameLocator- Parameters:
testId- Id to locate the element by.
-
getByTestId
public Locator getByTestId(java.util.regex.Pattern testId)
Description copied from interface:FrameLocatorLocate element by the test id.**Usage**
Consider the following DOM structure.
You can locate the element by it's test id:
page.getByTestId("directions").click();**Details**
By default, the
data-testidattribute is used as a test id. UseSelectors.setTestIdAttribute()to configure a different test id attribute if necessary.- Specified by:
getByTestIdin interfaceFrameLocator- Parameters:
testId- Id to locate the element by.
-
getByText
public Locator getByText(java.lang.String text, FrameLocator.GetByTextOptions options)
Description copied from interface:FrameLocatorAllows locating elements that contain given text.See also
Locator.filter()that allows to match by another criteria, like an accessible role, and then filter by the text content.**Usage**
Consider the following DOM structure:
You can locate by text substring, exact string, or a regular expression:
// Matches <span> page.getByText("world") // Matches first <div> page.getByText("Hello world") // Matches second <div> page.getByText("Hello", new Page.GetByTextOptions().setExact(true)) // Matches both <div>s page.getByText(Pattern.compile("Hello")) // Matches second <div> page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type
buttonandsubmitare matched by theirvalueinstead of the text content. For example, locating by text"Log in"matches<input type=button value="Log in">.- Specified by:
getByTextin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByText
public Locator getByText(java.util.regex.Pattern text, FrameLocator.GetByTextOptions options)
Description copied from interface:FrameLocatorAllows locating elements that contain given text.See also
Locator.filter()that allows to match by another criteria, like an accessible role, and then filter by the text content.**Usage**
Consider the following DOM structure:
You can locate by text substring, exact string, or a regular expression:
// Matches <span> page.getByText("world") // Matches first <div> page.getByText("Hello world") // Matches second <div> page.getByText("Hello", new Page.GetByTextOptions().setExact(true)) // Matches both <div>s page.getByText(Pattern.compile("Hello")) // Matches second <div> page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE))**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type
buttonandsubmitare matched by theirvalueinstead of the text content. For example, locating by text"Log in"matches<input type=button value="Log in">.- Specified by:
getByTextin interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByTitle
public Locator getByTitle(java.lang.String text, FrameLocator.GetByTitleOptions options)
Description copied from interface:FrameLocatorAllows locating elements by their title attribute.**Usage**
Consider the following DOM structure.
You can check the issues count after locating it by the title text:
assertThat(page.getByTitle("Issues count")).hasText("25 issues");- Specified by:
getByTitlein interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
getByTitle
public Locator getByTitle(java.util.regex.Pattern text, FrameLocator.GetByTitleOptions options)
Description copied from interface:FrameLocatorAllows locating elements by their title attribute.**Usage**
Consider the following DOM structure.
You can check the issues count after locating it by the title text:
assertThat(page.getByTitle("Issues count")).hasText("25 issues");- Specified by:
getByTitlein interfaceFrameLocator- Parameters:
text- Text to locate the element for.
-
last
public FrameLocator last()
Description copied from interface:FrameLocatorReturns locator to the last matching frame.- Specified by:
lastin interfaceFrameLocator
-
locator
public Locator locator(java.lang.String selector, FrameLocator.LocatorOptions options)
Description copied from interface:FrameLocatorThe method finds an element matching the specified selector in the locator's subtree. It also accepts filter options, similar toLocator.filter()method.- Specified by:
locatorin interfaceFrameLocator- Parameters:
selector- A selector or locator to use when resolving DOM element.
-
locator
public Locator locator(Locator selectorOrLocator, FrameLocator.LocatorOptions options)
Description copied from interface:FrameLocatorThe method finds an element matching the specified selector in the locator's subtree. It also accepts filter options, similar toLocator.filter()method.- Specified by:
locatorin interfaceFrameLocator- Parameters:
selectorOrLocator- A selector or locator to use when resolving DOM element.
-
nth
public FrameLocator nth(int index)
Description copied from interface:FrameLocatorReturns locator to the n-th matching frame. It's zero based,nth(0)selects the first frame.- Specified by:
nthin interfaceFrameLocator
-
-