Case insensitive xpaths

6,885 views
Skip to first unread message

Getafix

unread,
Mar 30, 2010, 7:51:15 PM3/30/10
to Selenium Users
Hello everyone

Can you please let me know to to write xpaths having the text
attribute case-insensitive
Like for the below example.

xpath=//a[text()='MANIFEST']

Thanks

Ritesh

unread,
Mar 31, 2010, 8:06:30 AM3/31/10
to Selenium Users
Hi,

you can do this by storing the text, just go through bellow code.

String text = selenium.getText("your xpath");
if(text.trim().equalsIgnoreCase("MANIFEST"))
{
true;
}
else
{
false;
}

Thanks
Ritesh

Mark Collin

unread,
Apr 1, 2010, 4:44:16 AM4/1/10
to seleniu...@googlegroups.com
That's not really answering the OP's question.

Try this instead:

//a[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz')='manifest']

> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/selenium-users?hl=en.
>
>


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

darrell

unread,
Apr 1, 2010, 10:21:33 AM4/1/10
to Selenium Users
The standard trick to compare strings and ignore case is to convert
the unknown string to all uppercase or all lowercase then compare it
to a known string. Thus your example would become:

xpath=//a[lower-case(text())='MANIFEST']

This of course only works if your browser supports XPath 2.0:
http://www.w3.org/2005/xpath-functions/#lower-case. If it does not,
you'll have to use the XPath 1.0 function translate as Mark
demonstrates.

Darrell

Gopi Ganesasundaram

unread,
Apr 2, 2010, 7:21:15 AM4/2/10
to seleniu...@googlegroups.com
Thanks very much Mark ! Your solution works perfectly !
I will be needing to use case-insensitive xpaths more frequently because i would be locating elements that has texts like Manifest ,MAnifest,manifest and MANIFEST
Thanks Darrell for your solution and link !
However my browser(s) do not support the xpath 2.0 unfortunately



ravi teja

unread,
Sep 26, 2012, 5:59:01 AM9/26/12
to seleniu...@googlegroups.com
Hi Mark , 

I am having similar requirement , i need to click a checkbox , i will get the checkbox name dynamically during the program execution. I need to select the checkbox in the application ignoring case 

sensitivity , i have tried  

selenium.click("css=td[class='dxeListBoxItem dxeT']:contains("regexpi:"+str+"")");

but it is highlighting as error in eclipse . 
Please help me in solving this.

To describe breifly my requirement ,  during the flow of  program execution i will get the name of the checkbox to be selected in application i got the checkbox name as "Inactive" , i stored it in a string . 

when i passed this string variable to click in the main applciation it is throwing  error like element not found because in the application  .. the checkbox is named as "INACTIVE" . hence it is failing to 

recognize it . how can i make it case insensitive so that it can identify the check box in any case. 

ThankS & Regards
Ravi Teja P.  



On Thursday, April 1, 2010 2:14:16 PM UTC+5:30, Mark Collin wrote:
That's not really answering the OP's question.

Try this instead:

//a[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz')='manifest']

> Hi,
>
> you can do this by storing the text, just go through bellow code.
>
> String text = selenium.getText("your xpath");
> if(text.trim().equalsIgnoreCase("MANIFEST"))
> {
>   true;
> }
> else
> {
>   false;
> }
>
> Thanks
> Ritesh
>

> On Mar 31, 4:51�am, Getafix <ashg...@gmail.com> wrote:
>> Hello everyone
>>
>> Can you please let me know to to write xpaths having the text
>> attribute case-insensitive
>> Like for the below example.
>>
>> xpath=//a[text()='MANIFEST']
>>
>> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/selenium-users?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages