Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding element using attribute ignoring case

Is there any way to find element using an attribute which must not be case sensitive?

Think that, I want to find element by a title like this:

driver.findElement(By.cssSelector("input[title='This is a Test Title']")).sendKeys("Test");

But change in the title text won't affect my WebElement.

like image 312
optimistic_creeper Avatar asked Nov 15 '25 06:11

optimistic_creeper


2 Answers

You can xpath to achieve this. look at below example.

driver.findElement(By.xpath(".//input[translate(@title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'this is my title']")).sendKeys("Test");

The above xpath will convert all uppercase letters from title to lower case and check if it is equal to given value.

like image 132
Sudharsan Selvaraj Avatar answered Nov 17 '25 21:11

Sudharsan Selvaraj


It is possible to locate the element ignoring the case sensitivity of the attribute values using the character i or I after the value.

"input[title='This is a Test Title'] i")

you can refer : http://pragmatictestlabs.com/2021/01/05/mastering-css-for-selenium-test-automation-2/

like image 29
Directionsky Avatar answered Nov 17 '25 19:11

Directionsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!