How to return an entire column with Selenium?

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

I 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 that there are several elements.

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

Please, kindly help, thank you very much!

+3
source share
1 answer

You will need to iterate over 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 save them for future reference.

+5
source

Source: https://habr.com/ru/post/1744105/


All Articles