2

Robot framework- xpath - how to use translate() function Consider tc1.robot file as below:

...
*** Test Cases ***
LoginTest
    ...
    sleep   5
    click element       xpath://input[matches(@placeholder,'username','i')]

How to use translate() function to do case insensitive search in the above line? i.e. it should match 'username' text in any combination case - mostly username, Username, USERNAME etc.

2
  • I suppose the framework relies on the xpath of the browser you are using. If so you can not use matches. And your question is about translate(). What do you want to translate into what? Commented Jul 14 at 9:26
  • @SiebeJongebloed - most likely OP wants to do case insensitive search and the library underneath is selenium's python bindings. Last time i checked, no browsers supported xpath 2.0 so translate() is typically used to do case conversion. Commented Jul 15 at 9:52

3 Answers 3

1

In XPath 1.0 you can do case-insensitive equality matching using

//input[translate(., 'ABCDE...XYZ', 'abcde...xyz') = 'username']

That only handles the English alphabet, obviously.

Sign up to request clarification or add additional context in comments.

Comments

1

In Xpath 1.0 use:

//input[translate(@placeholder, 
                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
                  'abcdefghijklmnopqrstuvwxyz') 
         = 'username']

In Xpath version >= 2.0 use:

//input[lower-case(@placeholder) = 'username']

2 Comments

This is what I was trying to understand - got it. this code line worked fine as it is. Thanks - This is useful.
Glad it helped, Narendra. Maybe accept this answer? :)
0

You could use this xpath:


//input[contains('|username|Username|USERNAME|',concat('|',@placeholder,'|'))]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.