When I tried to get text of particular element which is returning all small letters. Hence my assertion has failed. kindly help me to get actual innertext and please let me know is there any other methods available to validate case sensitive inner text.


java.lang.AssertionError: expected [All content one platform] but found [all content one platform]


@FindBy(xpath ="//*[@class='promo__info']/h2")
WebElement AllContent;
String contentText = AllContent.getText();
    System.out.println("***********************" + contentText);
    Assert.assertEquals(contentText,"All content one platform");


<h2 data-v-31d5644f="">
      All content one platform
  • Which version you are using? Commented Aug 10, 2022 at 12:54
  • 1
    What is rendered on the page actually? You may have capitalized text in source but client side scripts (for example) could change the case. So getText actually returnes what is rendered rather than what's in the sources.
    – Alexey R.
    Commented Aug 10, 2022 at 15:35
  • I'm using selenium testng 7.5. Commented Aug 11, 2022 at 6:25
  • 1
    As mentioned by Alexey R. it can be an issue with capitalized text. Share your CSS and possibly a screenshot of what exactly is displaying in your web page as your browser's console to further understand and help you. Commented Aug 19, 2022 at 5:17

2 Answers 2


getText() :

  • This selenium method is working as expected for me and returned exact text instead of all text in lower case enter image description here

  • You can see text printed is actual text returned.

  • Another way to try using .getAttribute("value") This might not intended for same purpose as your field is not inout field, but can give a try for


There are multiple workarounds to handle such scenarios while doing web automation using Selenium. While working in software functional testing and frameworks in multiple languages below are the 02 top approaches widely used -

Method 1 - Use Java Inbuilt methods

Step 1 - Fetch the text using getText() method

Step 2 - Compare it with required string using Java's in built methods like equalsIgnoreCase() and store result as a boolean

Step 3 - Assert the boolean value using TestNg's Assert.assertTrue() method.

Method 2 - getAttribute() method of Selenium Now here try with conventional "value" attribute and if it doesn't work, try with all other attributes which gives string output in required format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.