This thread is trying to answer question "Why is the button click in a Playwright test not being executed, and how can it be resolved?"
test('Accordion Component', async ({page}) => {
const header: string | null = await page.locator(`[data-test="accordion-0"]`).textContent();
expect(typeof header).toBe('string');
console.log("header", header);
const button: Locator = page.locator(`[data-test="accordion-button-0"]`);
await button.click();
const details: Locator = page.locator(`[data-test="accordion-details-0"]`);
console.log("details", details);
const isDetailsVisible: boolean = await details.isVisible();
console.log("isDetailsVisible", isDetailsVisible);
});
I just had a similar issue with an AntDesign Collapse
component. The transitioning element would cause playwright to "miss" the element I was trying to interact with.
Not saying this will work for you, but my solution was to find the element by its transitioning class name and wait for a hidden state. Most of the libraries that handle accordion-type elements will give the closed, transitioning, and opened states of the element different classes. In my case, the transitioning class was ant-motion-collapse-enter-active
, so I just waited for that to be hidden before continuing.
Ex:
const transitioningList = page.locator(".ant-motion-collapse-enter-active");
await transitioningList.waitFor({ state: "hidden" });
Of course, if that doesn't work, there's always page.waitForTimeout
๐
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].