Skip to content

Commit 04158db

Browse files
authored
cherry-pick(#1131): fix: implement LocatorImpl.getByRole (#1132)
Fixes #1130
1 parent e47d0ab commit 04158db

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public Locator getByPlaceholder(Pattern text, GetByPlaceholderOptions options) {
245245

246246
@Override
247247
public Locator getByRole(AriaRole role, GetByRoleOptions options) {
248-
return null;
248+
return locator(getByRoleSelector(role, options));
249249
}
250250

251251
@Override

playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,12 @@ void getByRoleEscaping() {
171171
asList("<a href=\"https://playwright.dev\">he llo 56</a>"),
172172
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName(" he \n llo 56 ").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)"));
173173
}
174+
175+
@Test
176+
void locatorGetByRole() {
177+
page.setContent("<div><button>Click me</button></div>");
178+
assertEquals(
179+
asList("<button>Click me</button>"),
180+
page.locator("div").getByRole(AriaRole.BUTTON).evaluateAll("els => els.map(e => e.outerHTML)"));
181+
}
174182
}

0 commit comments

Comments
 (0)