在 Selenium WebDriver 的属性中使用 XPath 通配符 [英] Using XPath wildcards in attributes in Selenium WebDriver

查看:55
本文介绍了在 Selenium WebDriver 的属性中使用 XPath 通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

I want to replace the j_idt number with a wildcard because the number is dynamic. I'm looking for something like this:

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

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

I don't know how to solve that issue. Is my idea even possible?

推荐答案

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

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

这篇关于在 Selenium WebDriver 的属性中使用 XPath 通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆