How to return a whole column with Selenium?
I know that Selenium has a built-in method getTable("tableName.row.column")开发者_如何学C 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!
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
精彩评论