Skip to content

Commit

Permalink
fix(locator): fix is_enabled method (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Feb 5, 2025
1 parent ab02bb0 commit c88f12a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion playwright/_impl/_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ async def is_editable(self, timeout: float = None) -> bool:

async def is_enabled(self, timeout: float = None) -> bool:
params = locals_to_params(locals())
return await self._frame.is_editable(
return await self._frame.is_enabled(
self._selector,
strict=True,
**params,
Expand Down
9 changes: 8 additions & 1 deletion tests/async/test_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ async def test_fill_textarea(page: Page, server: Server) -> None:
assert await page.evaluate("result") == "some value"


#
async def test_is_enabled_for_non_editable_button(page: Page) -> None:
await page.set_content(
"""
<button>button</button>
"""
)
button = page.locator("button")
assert await button.is_enabled() is True


async def test_fill_input(page: Page, server: Server) -> None:
Expand Down
18 changes: 3 additions & 15 deletions tests/async/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,15 @@ async def test_locators_is_enabled_and_is_disabled_should_work(page: Page) -> No
)

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

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

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


Expand Down
18 changes: 3 additions & 15 deletions tests/sync/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,15 @@ def test_locators_is_enabled_and_is_disabled_should_work(page: Page) -> None:
)

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

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

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


Expand Down

0 comments on commit c88f12a

Please sign in to comment.