admin管理员组文章数量:1394134
if (casper.exists(x('//p[@class="classname" and (contains(text(), "this is my string."))]'))){
//code
}
I want to be able to match "this is my string."
as well as "thiS is My striNg."
.
I couldn't find any functions to do this. It is okay to change the text on the screen to lowercase or uppercase and then match but it shouldn't change all the text rather just the string that I want to search for. But I couldn't find how to do this.
if (casper.exists(x('//p[@class="classname" and (contains(text(), "this is my string."))]'))){
//code
}
I want to be able to match "this is my string."
as well as "thiS is My striNg."
.
I couldn't find any functions to do this. It is okay to change the text on the screen to lowercase or uppercase and then match but it shouldn't change all the text rather just the string that I want to search for. But I couldn't find how to do this.
1 Answer
Reset to default 6It seems that Casper JS only supports XPath 1.0. In that case you can't use the lower-case()
function, but you can use translate()
to replace a collection of characters with their lower-case representation. You need to include all the characters that can have upper and lowercase representations (including accented characters, for example), in order.
For example: the expression:
translate('street', 'tse', 'sto')
replaces each t
for an s
, each s
for a t
and each e
for an o
. It results in:
tsroos
So you can use
translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')
to translate all upper-case ASCII characters in your string to lower-case. Applying this you your example, you can use:
//p[@class="classname"
and (contains(translate(text(),"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz"),
"this is my string."))]
本文标签:
版权声明:本文标题:javascript - How to use ignorecase when using contains(text(), "string") in XPath expressions in CasperJS? - S 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744085083a2588366.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论