← Back to Discord Forum

Unstable Test - 'update' DOM?


i have a flaky test which fails like 2 out of 10 times with the Error:

locator.click: DOMException: Failed to execute 'querySelectorAll' on 'Document': '#randomID' is not a valid selector.

The locator exists but i don't understand why it fails. I use await page.locator(#${randomID}).click(); which should already auto-wait. How can i improve this test?

This thread is trying to answer question "How can I improve a flaky test that fails due to a DOMException error caused by an invalid selector?"

6 replies

You could look to add a await page.waitForSelector(#${randomID}); before clicking

I know the click element auto waits but it may be that it is not yet added to the DOM or is being dynamically loaded.

I thin i figured out why. It took me 2 days lol the randomID was a mix of Chars and Numbers. I found a post on stackoverflow that said:

"..But querySelector method uses CSS3 selectors for querying the DOM and CSS3 doesn't support ID selectors that start with a digit:"

Now i changed it so that it starts always with a Char

But shouldn't the playwirght locator handle this?

It follows CSS specification but you'd probably have had to log the error to see the reason

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.