Testcafe - How to write testcafe selector to identify element with class contains

884 Views Asked by At

I need to write the location of an element in page which has just the tag name and only 1 attribute - class and the class value has number characters which is dynamic so I have to use contains to specify the element.

Could not traverse from parent node as it is a list with similar parent name.

Any Suggestions please??

1

There are 1 best solutions below

2
On

You can use the Selector.withAttribute method.

For example, the following code finds an input with an attribute, which name ends with 'testId' and clicks on it.

await t.click(Selector('input').withAttribute(/.*testid/);