Skip to content

[🐛 Bug]: WebElement.Text returns wrong capitalized text when underscores are used #17664

Description

@lastas

Description

Selenium 4.44.0.
C# (.NET) project.
Element with text test_text has style style="text-transform: capitalize;". The text displays on UI in browser as Test_text (as expected).

Expected result: element.Text should return the same text as user has on UI - i.e. Test_text.
Actual result: element.Text returns Test_Text (i.e. unexpected capitalized symbol after underscore).

See attached HTML file for more details: test.html

Note: can be related to already closed #14271 (but still reproduced against latest Selenium version 4.44.0, C#).

Reproducible Code

//<ItemGroup>
//   <PackageReference Include="Selenium.WebDriver" Version="4.44.0" />
//   <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="149.0.7827.5500" />
// </ItemGroup>

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
	public class Program
	{
		public static void Main(string[] args)
		{
			var htmlPath = Path.Combine("PATH_TO_FILE_HERE", "test.html");
			var fileUrl = new Uri(Path.GetFullPath(htmlPath)).AbsoluteUri;

			var options = new ChromeOptions();

			using var driver = new ChromeDriver(options);
			driver.Navigate().GoToUrl(fileUrl);

			var element = driver.FindElement(By.CssSelector("div"));
			Console.WriteLine("Text: " + element.Text);

			driver.Quit();
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions