在 Selenium WebDriver 的属性中使用 XPath 通配符



我想在我的属性中使用通配符。例如,这是我的常规XPath:

//input[@id='activation:j_idt84:voId:1']`

我想用通配符替换j_idt数字,因为该数字是动态的。我正在寻找这样的东西:

//input[@id='activation:*:voId:1']

我不知道如何解决这个问题。我的想法可能吗?

不幸的是,

XPath中没有字符串通配符。但是,您可以使用多个contains()starts-with()来过滤此类内容。

//input[starts-with(@id, 'activation:') and contains(@id, ':voId:1')]

此外,这个答案也可能有用: 硒:是否可以在硒定位器中使用正则表达式

您可以使用 XPath 2.0 中提供的 matches 函数使用字符串通配符:

//input[matches(@id, 'activation:.*:voId:1')]

最新更新