I am getting some strange behavior with the .click()
method in a large application built using the angular framework.
When I first click on the locator assigned to next_button
the correct button is clicked during the test.
The second click on next_button
is on a different button.
The third click on next_button
is on the correct button again.
When I use the record test feature, and click on the button twice, the locator does not change, and the locator being clicked on for the second call is:
page.getByRole('button').filter({ hasText: 'navigate_next' }).first()
Here is the part of the test where I am getting the strange behavior:
const next_button = page.getByRole('button').filter({ hasText: 'navigate_next' }).nth(2);
await next_button.click();
await expect(page.getByText('Results 11 - 20')).toBeVisible();
await next_button.click(); // this clicks a different button
await next_button.click(); // this click the correct button
await expect(page.getByText('Results 21 - 30')).toBeVisible();
await expect(page.getByRole('button').filter({ hasText: 'navigate_next' }).nth(2)).toBeDisabled();
Any help and explanations as to why this is happening would be GREATLY appreciated!