Testcafe:有没有一种方法可以添加多个文本作为 Selector().withText(text) 的输入 - 当应用程序支持多种语言时出现问题

Testcafe: Is there a way to add more than one text as an input for the Selector().withText(text) - Issue when application supporting multiple language

使用 : Selector().withText(text) -> 定位元素是理想的定位方式,如果我们没有任何其他与元素匹配的标签名称,但当应用程序支持多种语言时,我,如果超过 1 种语言,则文本字段会因选择的不同语言而异。

可能很少有人建议从前一个元素或后一个元素遍历和查找,但是例如让文本是一条警告消息,它根据用户输入而变化,有时它可能是 无效的用户名,有时可能是未注册用户,没有准确的文本定位将无法通过测试。

有没有建议添加多个文本,比如在 xpath 中 //*[text()='abc' || text()='xyz'] 在 testcafe ?

您可以尝试使用正则表达式来处理这种情况,

Selector("element").withText(/text1|text2|text3/);

您还可以 select 基于其属性的元素。 https://devexpress.github.io/testcafe/documentation/reference/test-api/selector/withattribute.html