如果元素是动态元素,如何定义选择器

How to define an selector if the elements are dynamic element

下面 img 上的代码片段

我想在 p clas = jss94 jss102 jss127 jss264 jss265 上断言文本 这个 class 是动态的,它之前的所有 class 也是动态的。那么如果上面没有静态 id/class/text,如何获取文本或如何 select 元素?

查看 select 具有动态标识符的元素的方法 here

您可以使用withAttribute方法:

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

请参考以下内容:

  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