usr4896260
usr4896260

Reputation: 1507

Selenium ChromeDriver with xpath using contains and lowercase

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?

Upvotes: 0

Views: 868

Answers (1)

Sathish
Sathish

Reputation: 360

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...

Upvotes: 1

Related Questions