1

Is there a way to match an attribute in case-insensitive fashion in XPath 1.0?

For example if I have this

<input type="submit"></input>
<input type="Submit"></input>
<input type="SUBMIT"></input>

I can use //input[@type='submit'] but it will match only the first element.

Is there a way to match all of the elements regardless case?

Pithikos
  • 18,827
  • 15
  • 113
  • 136
  • possible duplicate of [case-insensitive matching in xpath?](http://stackoverflow.com/questions/2893551/case-insensitive-matching-in-xpath) – alecxe Sep 16 '14 at 15:48
  • @alecxe no. All solutions in the link is for XPath 2. – Pithikos Sep 16 '14 at 15:53
  • Hm, arguable. In the best-scored answer there is a link to the [`translate()` based hack](http://stackoverflow.com/questions/1625446/problem-with-upper-case-and-lower-case-xpath-functions-in-selenium-ide/1625859#1625859) there. – alecxe Sep 16 '14 at 15:53
  • @alecxe that solution doesn't work for me. If I use `translate()` it will match either the first or last element, not all. – Pithikos Sep 16 '14 at 16:01
  • Then you are not doing it right... – BeniBela Sep 16 '14 at 16:11
  • @BeniBela thanks for the help. Very constructive feedback. – Pithikos Sep 16 '14 at 16:14
  • @Pithikos :) Though, as you see, the thread is very close to be duplicate. And thanks for sharing the solution. – alecxe Sep 16 '14 at 17:02

1 Answers1

1

I worked it out actually. It seems that @attribute can be used in place of strings. In that case

//input[translate(@type, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('submit', 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')]

Will give back all input elements where the value to type matches "submit", in case-insensitive fashion.

Pithikos
  • 18,827
  • 15
  • 113
  • 136