我想在我的属性中使用通配符。例如,这是我的常规 XPath:
//input[@id='activation:j_idt84:voId:1']`
我想j_idt
用通配符替换数字,因为数字是动态的。我正在寻找这样的东西:
//input[@id='activation:*:voId:1']
我不知道如何解决这个问题。我的想法甚至可能吗?
不幸的是,XPath 中没有字符串通配符。但是,您可以使用多个contains()
andstarts-with()
来过滤这样的内容。
//input[starts-with(@id, 'activation:') and contains(@id, ':voId:1')]
此外,这个答案也可能有用:selenium: Is it possible to use the regexp in selenium locators
您可以matches
使用XPath 2.0 中提供的函数来使用字符串通配符:
//input[matches(@id, 'activation:.*:voId:1')]