Skip to content

fix(locator): fix is_enabled method #2732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading