diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorUtils.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorUtils.java index 12c53ab8..7985da9d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorUtils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorUtils.java @@ -118,7 +118,7 @@ public class LocatorUtils { // cssEscape(value).replace(/\\ /g, ' ') // However, our attribute selectors do not conform to CSS parsing spec, // so we escape them differently. - return '"' + value.replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i"); + return '"' + value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + '"' + (exact ? "" : "i"); } private static String toJsRegExp(Pattern pattern) { diff --git a/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java b/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java index 86d4bb1d..c261a2f9 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestSelectorsGetBy.java @@ -1,5 +1,6 @@ package com.microsoft.playwright; +import com.microsoft.playwright.assertions.LocatorAssertions; import com.microsoft.playwright.options.AriaRole; import org.junit.jupiter.api.Test; @@ -147,6 +148,11 @@ public class TestSelectorsGetBy extends TestBase { assertThat(page.getByPlaceholder("hello my\nworld")).hasAttribute("id", "control"); assertThat(page.getByAltText("hello my\nworld")).hasAttribute("id", "control"); assertThat(page.getByTitle("hello my\nworld")).hasAttribute("id", "control"); + + page.setContent("
Text here
"); + assertThat(page.getByTitle("my title", new Page.GetByTitleOptions().setExact(true))).hasCount(1, new LocatorAssertions.HasCountOptions().setTimeout(500)); + assertThat(page.getByTitle("my t\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500)); + assertThat(page.getByTitle("my t\\\\itle", new Page.GetByTitleOptions().setExact(true))).hasCount(0, new LocatorAssertions.HasCountOptions().setTimeout(500)); } @Test @@ -178,6 +184,16 @@ public class TestSelectorsGetBy extends TestBase { assertEquals( asList("he llo 56"), page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName(" he \n llo 56 ").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)")); + + assertEquals( + asList(""), + page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Click me").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)")); + assertEquals( + asList(), + page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Click \\me").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)")); + assertEquals( + asList(), + page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Click \\\\me").setExact(true)).evaluateAll("els => els.map(e => e.outerHTML)")); } @Test