I have an HTML with the following element:
<a href="index.html" style="text-transform: uppercase;">index</a>
I'm using selenium-java 4.8.2, Chrome 112 and JUnit 5.9.2, and trying to find this element via WebDriver's linkText locator.
public void testMethod() {
driver.get("<myUrl>");
driver.findElement(By.linkText("index")).click();
}
And it does not work. After some investigation I found that when I replace By.linkText("index") with By.linkText("INDEX"), it works, so it looks like the text-transform CSS styling is applied before the element is found.
On the other hand, using the good old XPath works.
driver.findElement(By.xpath("//a[text()='index']")).click();
Does anyone have an idea on this topic? I thought that CSS transformations should not be applied when finding an element using any selector strategy using WebDriver, but I could not find any explicit information regarding this topic.