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."))]