0

I'm new to selenium and xpath and I'm trying to check if a span contains certain text, while ignoring the case. I've tried referencing solutions here and here but without success. I have the following:

var driver = new ChromeDriver(DRIVER_LOCATION, options);
string name = "doe, john";
// xpath = "(//span[contains(lower-case(text()), lower-case('doe, john'))][contains(@class, 'token-label')])"
string xpath = $"(//span[contains(lower-case(text()), lower-case('{name}'))][contains(@class, 'token-label')])";
var element = driver.FindElement(By.XPath(xpath));

The the text in the element has "Doe, John" and therefore, fails to find the element. What is the proper way to ignore the case while using contains in xpath for selenium?

usr4896260
  • 1,427
  • 3
  • 27
  • 50
  • 2
    `lower-case()` is for XPath 2.0 but ChomeDriver is only XPath 1.0 – gangabass Feb 28 '18 at 16:36
  • 1
    Duplicate of [***case insensitive xpath contains() possible?***](https://stackoverflow.com/questions/8474031/case-insensitive-xpath-contains-possible) – kjhughes Feb 28 '18 at 17:31

1 Answers1

1

Chrome doesnot support lower-case keyword and you could use translate keyword as mentioned below

"//span//text()[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'"+ name + "')]". 

Hope this helps...

Sathish
  • 350
  • 3
  • 24