Webdriverio: Case insensitive selector for text?

Created on 12 Jan 2016  路  4Comments  路  Source: webdriverio/webdriverio

There was a brief discussion on gitter about this yesterday, but I am in a scenario where I know the front end stylesheets play with text, i.e capitalize, uppercase etc, and the test data which is provided is not always going to be in the same case.

Now I believe Selenium only supports XPath 1 so you cannot use the upper/lower case functions there, and the only other approach I know of is the transform approach (all on http://stackoverflow.com/questions/17368189/xpath-lower-case-to-get-a-collection-of-lowercased-values)

So I was just wondering if there was a better way to do this? as ideally I just want a succinct way of saying a=blah where blah could be BlAH etc.

Question

Most helpful comment

there is no "correct case" in some test cases. and one way to approach a test "wrong" would be to create brittle requirements like very precise casing.

All 4 comments

is this situation still true? i've also found myself in a spot where i've got elements to select with case-insensitive text values. and i'm struggling to get this functionality going.

This is old so closing. But I think you should always select based on the correct case and update your test data. If you're not then I think your approach to the problem/test is wrong.

there is no "correct case" in some test cases. and one way to approach a test "wrong" would be to create brittle requirements like very precise casing.

const SELECTOR = '.my-selector';
const buttonText =  'blabla';

let elements = $$(`${SELECTOR}`);
const buttons = elements.filter(
  li =>
    li
      .getText()
      .toLowerCase()
      .indexOf(buttonText.toLowerCase()) > -1
);

const button = buttons[0];
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Windyq picture Windyq  路  4Comments

kiraLinden picture kiraLinden  路  3Comments

davidsoderberg picture davidsoderberg  路  4Comments

pfluegs picture pfluegs  路  4Comments

espekkaya picture espekkaya  路  3Comments