I have at least three options to click on a button:
await page.Locator("button", new() { HasText = "Создать" }).ClickAsync();
await page.GetByRole(AriaRole.Button, new() { Name = "Создать" }).ClickAsync();
await page.GetByText("Создать") .ClickAsync();
The page on which I do this, based on my practical observations, can give 2 options for this button in the HTML markup:
- selector:
#app-content > div > div > div._1hAP9 > div > div.f\\+e\\+A > button
xpath:/html/body/div[1]/div[1]/div[2]/div/div/div[4]/div/div[2]/button
- selector:
#app-content > div > div > div._1hAP9 > div > div > button
xpath:/html/body/div[1]/div[1]/div[2]/div/div/div[7]/div/div/button
At the same time, from the developer console document.querySelector
will find the button in both paths for both HTML variants. But from playwright, they sometimes work, sometimes they don't. At the same time, the execution continues to go further through the commands, as if the click was made, although, in fact, it does not occur (I observed the behaviour of the browser with the headless=false
parameter).
Also, the Force = true
parameter sometimes affects the behaviour of buttons, and sometimes nothing changes, the code continues to go further and crashes on the timeout of a component that has not yet appeared, because the button has not been pressed.
How can I make it so that this button is finally clicked ALWAYS?
although, in fact, it does not occur
how did you determine that? Are you sure the problem isn't the click handler, or whatever the page does after the click?crashes on the timeout of a component that has not yet appeared, because the button has not been pressed
how is that component displayed? – Bifocal