MCPcopy Index your code
hub / github.com/microsoft/playwright-python / escape_for_attribute_selector

Function escape_for_attribute_selector

playwright/_impl/_str_utils.py:62–76  ·  view source on GitHub ↗
(
    value: Union[str, Pattern], exact: bool = None
)

Source from the content-addressed store, hash-verified

60
61
62def escape_for_attribute_selector(
63 value: Union[str, Pattern], exact: bool = None
64) -> str:
65 if isinstance(value, Pattern):
66 return escape_regex_for_selector(value)
67 # TODO: this should actually be
68 # cssEscape(value).replace(/\\ /g, ' ')
69 # However, our attribute selectors do not conform to CSS parsing spec,
70 # so we escape them differently.
71 return (
72 '"'
73 + value.replace("\\", "\\\\").replace('"', '\\"')
74 + '"'
75 + ("s" if exact else "i")
76 )

Callers 3

get_by_test_id_selectorFunction · 0.90
get_by_role_selectorFunction · 0.90

Calls 1

Tested by

no test coverage detected