我们可以在xpath值中使用正则表达式吗? [英] Can we using regular expression in xpath value?

查看:410
本文介绍了我们可以在xpath值中使用正则表达式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在xpath值中使用正则表达式吗?我正在使用xpath值来标识网络上的自动化元素.

Can we using regular expression in xpath value? I am using xpath value to identify an element on web for automation.

我有以下:xpath值.

I have following :xpath value.

:xpath,'//*[@id="ngdialog4"]/div[2]/div[2]/table/tbody/tr/td[1]/input'

但是,最后一位4 ngdialog4不是恒定的,并且每次i持续变化 打开弹出窗口...我可以使用一些正则表达式来匹配任何数字吗?

But, the last digit 4 ngdialog4 is not constant and it keeps on changing each time i open pop-up... can i use some regular expression to match any digit?

推荐答案

理论上您可以使用matches(),但是它是

You could have theoretically used matches(), but it is a part of xpath 2.0, which webdriver doesn't support, see a detailed explanation here:

应用 starts-with() 而是检查:

Apply a starts-with() check instead:

//*[starts-with(@id, "ngdialog")]

这篇关于我们可以在xpath值中使用正则表达式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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