Currently, I have a Listbox on the page with an associated record count, scenarios would be as follows:

  • No Records
  • Displaying 1 Record(s)
  • Displaying 1-14 of X Records

However when I try getText() on this element it returns the above string plus all entries which exist in the listbox, see image:

Web App ListBox/Record Count

getText() returns the record count and every listbox entry for that page in question. e.g:

1-15 of 152 Records

Im making a generic method to return my record count in every scenario, my thought is to grab it and trim the string down by characters and run it through a few if statements to cover every possible scenario as the text can vary quite substantially based on the record count.

Am I mad? is there a much better way to handle this?

Div Code

  • Do you have the code for the listbox?
    – Swagin9
    Commented Jun 29, 2016 at 18:48
  • 1
    What is the code you're using to pull the text?
    – Swagin9
    Commented Jun 29, 2016 at 19:30
  • I am guessing you are using outer div to get text value. Can you expand div and try to locate just element which shows number of records. Commented Jun 29, 2016 at 19:52

1 Answer 1


You have to do some string manipulations to get the desired result

String text=driver.findElement(By.id(idOfRecordCountElement)).getText();
String desiredText=text.substring(0,text.indexOf("\n"));

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.