1

In selenium I used the following XPATH to find all elements which have the word ok:

//button[(((@value='ok')) or ((@value='Ok')) or ((@value='OK')))]

What if I want to find all buttons which start with the word ok? As an example OK1 is a match.

1 Answer 1

1

To find all elements which have the word ok you can modify as follows:

//button[@value='ok' or @value='Ok' or @value='OK']

and to find all elements which starts with the word ok you can use:

//button[starts-with(@value, 'ok') or starts-with(@value, 'Ok') or starts-with(@value, 'OK')]
Sign up to request clarification or add additional context in comments.

10 Comments

This is exact match :) plus I want them to start with ok
@john Checkout the updated answer and let me know the status.
Thanks I will test and accept very soon, just 2 side question, 1) I have noticed that some people use value and some use text, what's the difference? 2) Isn't there a way to do non-case sensitive search (instead of ok, OK, Ok, oK..)
You'd use starts-with(@value, 'ok') when the element is <button class="classname" value="ok">. You'd use starts-with(., 'ok') when the element is <button class="classname" value="abc">okJohn</button>
Worked like a charm thanks! but what about when I want to check exact match for: <button class="classname" value="IGNORE ME">ok</button>? do you do: //button[.='ok' or .='Ok' or .='OK']
|

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.