tags:

views:

25

answers:

1

Please see the below example. Whenever I use the i counter in the row then I see the below error message:

ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: table.rows[row] is undefined

public static String verifyLinkedSubmissions(String articleTitle){
  int rowCount=0;
  String trueString="Submission is found";
  String falseString="Submission is NOT found";
  rowCount=browser.getXpathCount("//TABLE[@id='LinkedWithRepeater']/TBODY/TR").intValue();

  for(int i=1; i<=rowCount; i++){
    String val=selenium.getTable("LinkedWithRepeater."+i+".4");
      if (val.equals(articleTitle)){
        log.info("Title name "+articleTitle+" is found");
        return trueString;
      }
  }

  log.error("Title name: "+articleTitle+" is NOT found in the Linked Submissions");
  return falseString;
}

If I hard code the row number then the script runs smooth. But I want to search for the particular articleTitle in case and verify it is present in the table or not.

The help is appreciated.

Thanks Aparna

+2  A: 

The problem here is the row and column reference in the getTable command must start at 0. You need to change your for loop so that it starts at 0 as follows:

for(int i=0; i<rowCount; i++) {
  String val=selenium.getTable("LinkedWithRepeater."+i+".4");
  if (val.equals(articleTitle)){
    log.info("Title name "+articleTitle+" is found");
    return trueString;
  }
}

Note that you may also need to change your column reference to 3 if you have not taken into account starting from 0.

Also, in your code sample you use both browser and selenium when using Selenium API commands. I assume this is a copy/paste mistake, but you may want to double check that.

See http://release.seleniumhq.org/selenium-core/1.0/reference.html#storeTable for details of the xTable commands.

Dave Hunt