[BUG] elementHandle.check: Unable to click checkbox
Context:
- Playwright Version: 1.8.0
- Operating System: Windows server 2016
- Node.js version: 14.15.3
- Browser: Chromium
- Extra: Error found in a Pipeline run (Azure DevOps)
Azure Devops Pipeline
jest-playwright-preset
Code Snippet
const element = await page.waitForSelector('input[type=checkbox][name=DontShowAgain]', { state: 'attached', timeout: 10000 }) await element.hover() await element.check()
Describe the bug
elementHandle.check: Unable to click checkbox =========================== logs =========================== attempting click action waiting for element to be visible, enabled and not moving element is visible, enabled and does not move scrolling into view if needed done scrolling checking that element receives pointer events at (476,416.21) element does receive pointer events performing click action click action done waiting for scheduled navigations to finish navigations have finished ============================================================ Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.:
31 | const element = await page.waitForSelector('input[type=checkbox][name=DontShowAgain]', { state: 'attached', timeout: 10000 })
32 | await element.hover()
> 33 | await element.check()
| ^
at Connection.sendMessageToServer (node_modules/playwright/lib/client/connection.js:69:15)
at Proxy.<anonymous> (node_modules/playwright/lib/client/channelOwner.js:44:61)
at node_modules/playwright/lib/client/elementHandle.js:171:47
at ElementHandle._wrapApiCall (node_modules/playwright/lib/client/channelOwner.js:72:34)
at ElementHandle.check (node_modules/playwright/lib/client/elementHandle.js:170:21)
at RadioInput.<anonymous> (src/components/form/inputs/radio.ts:33:23)
at fulfilled (src/components/form/inputs/radio.ts:5:58)
I just have had a random error that seems to not have any explanation (according to the logs) or any sign of how to be reproduced again. I run my tests every night on Azure DevOps and I tonight I got the error specified above. But the logs doesn't say why the checkbox couldn't be clicked.
This error means that checkbox was unchecked, Playwright clicked it, and checkbox is still unchecked. Something went wrong, might be a bug in Playwright, or in the page. It's hard to say what's going on, do you have repro script by any chance?
We should improve the error message though.
Unfortunately it occured in a Microsoft Login Page, "stay signed in" checkbox, so I cannot provide repro script. I have not been able no reproduce it again myself.
I can confirm this issue happens on Firefox too. Apparently the issue is something random. And happens on radio buttons only.
This code makes radio button checked though
await radio.evaluate(node => node.checked = true);
So what I ended up with, for now, is
await button.hover(); // to ensure actionability
try {
await button.check();
} catch {
await button.evaluate(node => node.checked = true);
}
In version v1.9 the error message has been changed to more descriptive Clicking the checkbox did not change its state. Closing this since we lack a reproducible scenario to investigate further.
Can confirm this still happens in some of our tests, approximately 1/20 test runs fails with such error in firefox. Playwright 1.20 + Python 3.8.10, running in CodeBuild.
> p.set_invoice_details(
start_date="01/01/2021",
end_date="01/01/2022",
frequency="Semi-Monthly",
invoice_terms="Net 10",
segment_by_parent_level=True,
segment_by_group_level=True,
)
tests/invoicing/test_invoice_template.py:93:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lib/capitalrx_finance_ui_automation/pom/invoicing/invoice_template.py:363: in set_invoice_details
self.page.locator(self.SEGMENT_BY_PARENT_LEVEL_CHECKBOX).set_checked(checked=segment_by_parent_level)
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/sync_api/_generated.py:13604: in set_checked
self._sync(
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/_impl/_locator.py:521: in set_checked
await self.check(
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/_impl/_locator.py:129: in check
return await self._frame.check(self._selector, strict=True, **params)
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/_impl/_frame.py:636: in check
await self._channel.send("check", locals_to_params(locals()))
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/_impl/_connection.py:39: in send
return await self.inner_send(method, params, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <playwright._impl._connection.Channel object at 0x7f6444d2d490>
method = 'check'
params = {'selector': "[data-testid='test__parent-level']", 'strict': True}
return_as_dict = False
async def inner_send(
self, method: str, params: Optional[Dict], return_as_dict: bool
) -> Any:
if params is None:
params = {}
callback = self._connection._send_message_to_server(self._guid, method, params)
if self._connection._error:
error = self._connection._error
self._connection._error = None
raise error
done, _ = await asyncio.wait(
{
self._connection._transport.on_error_future,
callback.future,
},
return_when=asyncio.FIRST_COMPLETED,
)
if not callback.future.done():
callback.future.cancel()
> result = next(iter(done)).result()
E playwright._impl._api_types.Error: Clicking the checkbox did not change its state
E =========================== logs ===========================
E waiting for selector "[data-testid='test__parent-level']"
E selector resolved to visible <input value="false" type="checkbox" id="parent-level" …/>
E attempting click action
E waiting for element to be visible, enabled and stable
E element is visible, enabled and stable
E scrolling into view if needed
E done scrolling
E performing click action
E click action done
E waiting for scheduled navigations to finish
E navigations have finished
E ============================================================
/root/.pyenv/versions/3.8.10/lib/python3.8/site-packages/playwright/_impl/_connection.py:63: Error
This is happening to me. I have a table of data, with each row having a checkbox. I wish to select two or more based on the id on the row. I'm using Version 1.20.2 in nodejs (javascript).
const test_data = { "users": [ {"id": "3845", "name": "Frank Smith"}, {"id": "4892", "name": "George Johnson"}];
await Promise.all(test_data.users.map( async (user) => {
const subLocator = page.locator('td', {hasText: user.id});
await page.locator('table tbody tr', {has: subLocator}).locator('input[type="checkbox"]').check();
});
It worked once in headed mode. Then it failed 3 times in a row. Then it failed another 4 times in a row in non-headed mode.
The table (for my example) is:
<table>
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Name</th>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="selectedId" /></td>
<td>4892</td>
<td>George Johnson</td>
</tr>
<tr>
<td><input type="checkbox" name="selectedId" /></td>
<td>3845</td>
<td>Frank Smith</td>
</tr>
</tbody>
</table>
@machtyn That snippet is checking two checkboxes at the same time. That's like a user connecting two mice and trying to click two different checkboxes simultaneously - they will interfere with each other. To avoid this problem, replace Promise.all with a loop:
const test_data = { "users": [ {"id": "3845", "name": "Frank Smith"}, {"id": "4892", "name": "George Johnson"}];
for (const user of test_data) {
const subLocator = page.locator('td', {hasText: user.id});
await page.locator('table tbody tr', {has: subLocator}).locator('input[type="checkbox"]').check();
}