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

Function test_get_by_escaping

tests/async/test_selectors_get_by.py:20–126  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

18
19
20async def test_get_by_escaping(page: Page) -> None:
21 await page.set_content(
22 """
23 <label id=label for=control>Hello my
24wo"rld</label><input id=control />"""
25 )
26 await page.eval_on_selector(
27 "input",
28 """input => {
29 input.setAttribute('placeholder', 'hello my\\nwo"rld');
30 input.setAttribute('title', 'hello my\\nwo"rld');
31 input.setAttribute('alt', 'hello my\\nwo"rld');
32 }""",
33 )
34 await expect(page.get_by_text('hello my\nwo"rld')).to_have_attribute("id", "label")
35 await expect(page.get_by_text('hello my wo"rld')).to_have_attribute(
36 "id", "label"
37 )
38 await expect(page.get_by_label('hello my\nwo"rld')).to_have_attribute(
39 "id", "control"
40 )
41 await expect(page.get_by_placeholder('hello my\nwo"rld')).to_have_attribute(
42 "id", "control"
43 )
44 await expect(page.get_by_alt_text('hello my\nwo"rld')).to_have_attribute(
45 "id", "control"
46 )
47 await expect(page.get_by_title('hello my\nwo"rld')).to_have_attribute(
48 "id", "control"
49 )
50
51 await page.set_content(
52 """
53 <label id=label for=control>Hello my
54world</label><input id=control />"""
55 )
56 await page.eval_on_selector(
57 "input",
58 """input => {
59 input.setAttribute('placeholder', 'hello my\\nworld');
60 input.setAttribute('title', 'hello my\\nworld');
61 input.setAttribute('alt', 'hello my\\nworld');
62 }""",
63 )
64 await expect(page.get_by_text("hello my\nworld")).to_have_attribute("id", "label")
65 await expect(page.get_by_text("hello my world")).to_have_attribute(
66 "id", "label"
67 )
68 await expect(page.get_by_label("hello my\nworld")).to_have_attribute(
69 "id", "control"
70 )
71 await expect(page.get_by_placeholder("hello my\nworld")).to_have_attribute(
72 "id", "control"
73 )
74 await expect(page.get_by_alt_text("hello my\nworld")).to_have_attribute(
75 "id", "control"
76 )
77 await expect(page.get_by_title("hello my\nworld")).to_have_attribute(

Callers

nothing calls this directly

Calls 12

set_contentMethod · 0.45
eval_on_selectorMethod · 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
to_have_countMethod · 0.45
text_contentMethod · 0.45
to_have_textMethod · 0.45
locatorMethod · 0.45

Tested by

no test coverage detected