[BUG] TestId Selector with regex does not find elements
See original GitHub issueContext:
- Playwright Version: 1.18.1
- Operating System: MacOS
- Node.js version: 16.13.1
- Browser: All
Code Snippet
test.only("should find testid with regex inside", async ({ page }) => {
await page.setContent(`<section data-testid="foo-09:00" >43543</section>`);
await page.setContent(`<section data-testid="foo-14:00" >43543</section>`);
const regex = new RegExp(`foo-[0-9]+:[0-9]+$`);
const locator = await page.locator(`data-testid=${regex}`).count();
console.log("locator count", locator); // returns 0
});
Describe the bug
I have a case with calendar component which has hour elements where some are disabled and some are not and I am trying to find first one that is not disabled. This works fine in Cypress, yet for Playwright returns 0 for the counts. Am I perhaps missing something?
Kind regards, Damevi
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How to get the element with the testid using react testing library?
Show activity on this post. Hi i want to access the first div with class "icon" using getByTestId. As you see from above...
Read more >About Queries | Testing Library
About Queries. Overview. Queries are the methods that Testing Library gives you to find elements on the page. There are several types of ......
Read more >Element Selectors | TestCafe Studio
Finds elements with an attribute of specific value. The method accepts both strings and regular expressions. For example, withAttribute('foo', ...
Read more >Working with selectors | Checkly
Text selectors, allowing users to select an element based on its text ... they should enable you to reference most, if not all,...
Read more >Queries | React Native Testing Library - Open Source
queryBy* queries return the first matching node for a query, and return null if no elements match. This is useful for asserting an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Regular expressions currently don’t work for
data-testid
matcher, only text.Can you try the following?
Search for the regex example here, you need the forward-slashes to use regex
/regex/
. https://playwright.dev/docs/selectors#text-selectorMaybe you need to set the
regex
const to be a string, without thenew RegExp