Selenide-检查链接文本是否匹配正则表达式
是否可以找到与正则表达式匹配的链接?
这里 https://demoqa.com/links 第二个链接每次都有一个随机名称,每次都会生成模式主页[A-ZA-Z] {5}
。
是否有任何方法可以检查链接文本是否匹配到正则是 substring + smth ? xpath // a [contains(text(),'substring')]
或$(partialLinkText(“ subString”)))
不适合,因为他们会选择两个HOME
和home [a-za-z] {5}
Is it possible to find a link that matches to the regular expression?
Here https://demoqa.com/links the 2nd link has a random name that is generated each time with the pattern Home[a-zA-Z]{5}
.
Is there any way to check if link text matches to the RegEx or simply contains substring + smth? XPath //a[contains(text(),'substring')]
or $(partialLinkText("substring"))
do not fit because they will select both Home
and Home[a-zA-Z]{5}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,正则应包括数字:
“ home [a-za-z \ d] {5}”
,我唯一可以的解决方案(至少目前)是迭代在所有包含home
的链接元素上:但是,如果您知道浏览器支持 XPATH 2.0 ,因此您可以使用
匹配
与Regex的功能:也许一无所获。浏览器中有关XPATH 2.0支持的以下链接:
First the regex should include numbers as well:
"Home[a-zA-Z\d]{5}"
, and the only solution I can thing of (at least for now), is to iterate over all link elements that containsHome
:But if you know that your browser supports XPath 2.0, so you can use
matches
function with regex:Maybe worth nothing the following links about XPath 2.0 support in browsers: