This code should work for you

protected List<String> getDates() {

  List<> DateElements = driver.findElements(By.xpath("//div[@class='dates']"));
  List<String> DateList = new <String>();

  for (WebElement element : DateElements ) {
      String dateParsed[] = element.getText().(",");
      if(dateParsed.length == 3){

  return DateList;

Here you split the value that returns your element.getText() using comma separator. Then you make sure you have the proper splitting (you should have 3 elements). After that you just get the 3rd element and trim the value to get rid of leading and trailing white-spaces.

Array size checking is required. Otherwise you might face the exception when you will try to take the value by the index that does not exist.

Source link


Please enter your comment!
Please enter your name here