Search code examples
csstestingdynamicfunctional-testingtestcafe

How to define an selector if the elements are dynamic element


snippet code on img below

I want to assert text on p clas = jss94 jss102 jss127 jss264 jss265 This class is dynamic, and all the class before it also dynamic. So how to get the text or how to select the element if there's no static id/class/text on it?


Solution

  • You can use the withAttribute method:

    .withAttribute('class', /jss\w+\sjss\w+/)
    

    Please refer to the following:

    1. https://github.com/DevExpress/testcafe/issues/4872#issuecomment-599919313
    2. https://regex101.com/r/VR5mJ0/1
    3. https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/examples-of-working-with-dom-elements.html#select-elements-with-dynamic-ids