Hello:
I have implemented a class inheriting from ActionBase. And I have defined a method that gets rows data from html table which has thead and tbody tags.
It returns all rows under tbody tag as a dict, using the cells in row under thead as keys.
I hope that it will be usefull.
Best regards,
Use:
rows = self.get_table_rows(context.browser_driver,element_key)
Method:
def get_table_rows(self, browser, table_selector):
# Get index row (keys)
keys = []
keys_count = int(browser.get_xpath_count(table_selector + "/thead/tr[1]/th"))
for keys_index in range(keys_count):
key = browser.selenium.get_table(table_selector + '/thead.0.%d' % ((keys_index))
keys.append(key)
# Get rows data
rows = []
row_count = int(browser.get_xpath_count(table_selector + "/tbody/tr"))
for row_index in range(row_count):
row = {}
cell_count = int(browser.get_xpath_count(table_selector +
"/tbody/tr[%d]/td" % \
(row_index + 1)))
for cell_index in range(cell_count):
cell = browser.selenium.get_table(table_selector + '/tbody.%d.%d' % (
row_index,
cell_index
))
row[keys[cell_index]]=cell
rows.append(row)
return rows