Skip to content

Commit c88f12a

Browse files
authored
fix(locator): fix is_enabled method (#2732)
1 parent ab02bb0 commit c88f12a

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

playwright/_impl/_locator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ async def is_editable(self, timeout: float = None) -> bool:
481481

482482
async def is_enabled(self, timeout: float = None) -> bool:
483483
params = locals_to_params(locals())
484-
return await self._frame.is_editable(
484+
return await self._frame.is_enabled(
485485
self._selector,
486486
strict=True,
487487
**params,

tests/async/test_fill.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ async def test_fill_textarea(page: Page, server: Server) -> None:
2222
assert await page.evaluate("result") == "some value"
2323

2424

25-
#
25+
async def test_is_enabled_for_non_editable_button(page: Page) -> None:
26+
await page.set_content(
27+
"""
28+
<button>button</button>
29+
"""
30+
)
31+
button = page.locator("button")
32+
assert await button.is_enabled() is True
2633

2734

2835
async def test_fill_input(page: Page, server: Server) -> None:

tests/async/test_locators.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,15 @@ async def test_locators_is_enabled_and_is_disabled_should_work(page: Page) -> No
128128
)
129129

130130
div = page.locator("div")
131-
with pytest.raises(
132-
Error,
133-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
134-
):
135-
assert await div.is_enabled()
131+
assert await div.is_enabled()
136132
assert await div.is_disabled() is False
137133

138134
button1 = page.locator(':text("button1")')
139-
with pytest.raises(
140-
Error,
141-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
142-
):
143-
assert await button1.is_enabled()
135+
assert await button1.is_enabled() is False
144136
assert await button1.is_disabled() is True
145137

146138
button1 = page.locator(':text("button2")')
147-
with pytest.raises(
148-
Error,
149-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
150-
):
151-
assert await button1.is_enabled()
139+
assert await button1.is_enabled()
152140
assert await button1.is_disabled() is False
153141

154142

tests/sync/test_locators.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,15 @@ def test_locators_is_enabled_and_is_disabled_should_work(page: Page) -> None:
126126
)
127127

128128
div = page.locator("div")
129-
with pytest.raises(
130-
Error,
131-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
132-
):
133-
div.is_enabled()
129+
assert div.is_enabled()
134130
assert div.is_disabled() is False
135131

136132
button1 = page.locator(':text("button1")')
137-
with pytest.raises(
138-
Error,
139-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
140-
):
141-
assert button1.is_enabled()
133+
assert button1.is_enabled() is False
142134
assert button1.is_disabled() is True
143135

144136
button1 = page.locator(':text("button2")')
145-
with pytest.raises(
146-
Error,
147-
match=r"Element is not an <input>, <textarea>, <select> or \[contenteditable\] and does not have a role allowing \[aria-readonly\]",
148-
):
149-
assert button1.is_enabled()
137+
assert button1.is_enabled()
150138
assert button1.is_disabled() is False
151139

152140

0 commit comments

Comments
 (0)