views:

113

answers:

1

I know that Selenium has a built-in method getTable("tableName.row.column") can return a cell conveniently. However how can I return a whole column?

I've tried getText() directly, however only the first cell was returned,

getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")

But getXpathCount() with the same Xpath expression showed there're multiple elements matched.

getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]") // result is 15

Please kindly help, many thanks!

+4  A: 

You will need to iterate through all the elements that match and store them somewhere.

so

int matches = selenium.getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")
string[] column;
for (int i = 1; i < matches;i++){
  column.add(selenium.getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')][" + i + "]");

}

This will go through the table with all the matches you want and then store them for later use

AutomatedTester
Thanks very much!Actually which I didn't know is that two square braces can go together like tr[contains(@class,'foo')][i] within Xpath expression.This is exactly what I'm looking for.Thanks again!
Kymair Wu