【问题标题】:How to target an element with random id in cypress如何在赛普拉斯中定位具有随机ID的元素 【发布时间】:2022-11-16 02:05:39 【问题描述】: How to target an element with random id 我尝试使用 xpath,但没有用 【问题讨论】: 标签: cypress 【解决方案1】: 使用 cy.contains() 单独或使用选择器按文本或正则表达式进行搜索。 cy.contains(/This text has random Id/i) 【讨论】: 【解决方案2】: 您可以将cy.contains 与选择器和文本结合使用。 cy.contains('p', 'This text has random Id') 【讨论】: