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("