Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive selector for text? #1017

Closed
grofit opened this issue Jan 12, 2016 · 4 comments
Closed

Case insensitive selector for text? #1017

grofit opened this issue Jan 12, 2016 · 4 comments
Labels

Comments

@grofit
Copy link

grofit commented Jan 12, 2016

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.

@worc
Copy link

worc commented May 10, 2018

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.

@WillBrock
Copy link
Member

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.

@worc
Copy link

worc commented Feb 19, 2019

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.

@omerdoron1
Copy link

omerdoron1 commented Mar 1, 2019

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];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants