MCPcopy Create free account
hub / github.com/microsoft/playwright-python / test_get_by_escaping

Function test_get_by_escaping

tests/sync/test_locator_get_by.py:154–197  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

152
153
154def test_get_by_escaping(page: Page) -> None:
155 page.set_content(
156 """<label id=label for=control>Hello my
157wo"rld</label><input id=control />"""
158 )
159 page.locator("input").evaluate(
160 """input => {
161 input.setAttribute('placeholder', 'hello my\\nwo"rld');
162 input.setAttribute('title', 'hello my\\nwo"rld');
163 input.setAttribute('alt', 'hello my\\nwo"rld');
164 }"""
165 )
166 expect(page.get_by_text('hello my\nwo"rld')).to_have_attribute("id", "label")
167 expect(page.get_by_text('hello my wo"rld')).to_have_attribute(
168 "id", "label"
169 )
170 expect(page.get_by_label('hello my\nwo"rld')).to_have_attribute("id", "control")
171 expect(page.get_by_placeholder('hello my\nwo"rld')).to_have_attribute(
172 "id", "control"
173 )
174 expect(page.get_by_alt_text('hello my\nwo"rld')).to_have_attribute("id", "control")
175 expect(page.get_by_title('hello my\nwo"rld')).to_have_attribute("id", "control")
176
177 page.set_content(
178 """<label id=label for=control>Hello my
179world</label><input id=control />"""
180 )
181 page.locator("input").evaluate(
182 """input => {
183 input.setAttribute('placeholder', 'hello my\\nworld');
184 input.setAttribute('title', 'hello my\\nworld');
185 input.setAttribute('alt', 'hello my\\nworld');
186 }"""
187 )
188 expect(page.get_by_text("hello my\nworld")).to_have_attribute("id", "label")
189 expect(page.get_by_text("hello my world")).to_have_attribute(
190 "id", "label"
191 )
192 expect(page.get_by_label("hello my\nworld")).to_have_attribute("id", "control")
193 expect(page.get_by_placeholder("hello my\nworld")).to_have_attribute(
194 "id", "control"
195 )
196 expect(page.get_by_alt_text("hello my\nworld")).to_have_attribute("id", "control")
197 expect(page.get_by_title("hello my\nworld")).to_have_attribute("id", "control")
198
199
200def test_get_by_role(page: Page) -> None:

Callers

nothing calls this directly

Calls 9

set_contentMethod · 0.45
evaluateMethod · 0.45
locatorMethod · 0.45
to_have_attributeMethod · 0.45
get_by_textMethod · 0.45
get_by_labelMethod · 0.45
get_by_placeholderMethod · 0.45
get_by_alt_textMethod · 0.45
get_by_titleMethod · 0.45

Tested by

no test coverage detected