Using XPath wildcards in attributes in Selenium WebDriver

前端 未结 2 1570
长发绾君心
长发绾君心 2021-01-01 15:51

I want to use Wildcards in my attributes. For example, this is my regular XPath:

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

I want to rep

相关标签:
2条回答
  • 2021-01-01 16:30

    Unfortunately there's no string wildcards in XPath. However you can use multiple contains() and starts-with() to filter things like this.

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

    Also, this answer could be useful too: selenium: Is it possible to use the regexp in selenium locators

    0 讨论(0)
  • 2021-01-01 16:31

    You can use string wildcards using the matches function which is available in XPath 2.0:

    //input[matches(@id, 'activation:.*:voId:1')]
    
    0 讨论(0)
提交回复
热议问题