Xpath“以"结束不起作用 [英] Xpath "ends-with" does not work

查看:35
本文介绍了Xpath“以"结束不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个动态 ID 名称总是以register"结尾的输入元素.到目前为止我试过这个

I am trying to find an input element with dynamic id name always ending with "register". So far I tried this

"//input[@id[ends-with(.,'register')]]"

还有这个

"//input[ends-with(@id,'register')]"

这些都不会产生元素.我究竟做错了什么?同时这有效:

none of these result in an element. What am I doing wrong? At the same time this works:

"//input[@id[contains(.,'register')]]"

以下是部分源码:

<td class="input">
<input id="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" name="m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register" class="aranea-checkbox" type="checkbox"> </td>

推荐答案

ends-with 函数是 xpath 2.0 的一部分,但浏览器(您表示您正在使用 chrome 进行测试)通常仅支持 1.0.因此,您必须自己使用 string-lengthsubstring 和 equals

The ends-with function is part of xpath 2.0 but browsers (you indicate you're testing with chrome) generally only support 1.0. So you'll have to implement it yourself with a combination of string-length, substring and equals

substring(@id, string-length(@id) - string-length('register') +1) = 'register'

这篇关于Xpath“以"结束不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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