What is the most effective method of storing the value in this string?

  • 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

  • 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"));

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2