I am trying to fetch data from html
table and convert it into dataframe
using robot framework
. I have created custom keyword to fetch data from data frame
locator = xpath://div[@class='virtualized-table-container scenario-manager-table duplicate-scenario-
This is html
<div class="virtualized-table-container scenario-manager-table duplicate-scenario-table">
<table>
<thead>
<tr class=""><th colspan="1" class="" style="text-align: center;"><span>Scenario Name</span></th><th colspan="1" class="" style="text-align: center;"><span>Channel</span></th><th colspan="1" class="" style="text-align: center;"><span>Retailer</span></th><th colspan="1" class="" style="text-align: center;"><span>Category</span></th><th colspan="1" class="" style="text-align: center;"><span>Cell</span></th><th colspan="1" class="" style="text-align: center;"><span>Author</span></th><th colspan="1" class="" style="text-align: center;"><span>Date Created</span></th><th colspan="1" class="" style="text-align: center;"><span>Date Modified</span></th></tr>
<tr class="secondary-header-row"><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"><div class="MuiGrid-root MuiGrid-item css-13bp0hq">Date Created</div></div></div></th><th colspan="1" class="last text-column" style="text-align: center;"><div class="MuiGrid-root MuiGrid-container css-hs2rr0"><div class="MuiGrid-root MuiGrid-container MuiGrid-item MuiGrid-grid-xs-auto change-text css-1coxso0"><div class="MuiGrid-root MuiGrid-item css-13bp0hq">Date Modified</div></div></div></th></tr>
</thead>
<tbody>
<tr class=""><td class="last text-column">New scenario 061023 (Duplicate)</td><td class="last text-column">channel2</td><td class="last text-column">retailer2, retailer4</td><td class="last text-column">All</td><td class="last text-column">cell1</td><td class="last text-column">test test</td><td class="last text-column">26th Oct 23</td><td class="last text-column">26th Oct 23</td></tr>
<tr class=""><td class="last text-column">New scenario 061023 123</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">test test</td><td class="last text-column">25th Oct 23</td><td class="last text-column">25th Oct 23</td></tr>
<tr class=""><td class="last text-column">New scenario 25102023</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">test test</td><td class="last text-column">25th Oct 23</td><td class="last text-column">25th Oct 23</td></tr>
<tr class="selected-row"><td class="last text-column">Copy of New 13102023</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">test test</td><td class="last text-column">13th Oct 23</td><td class="last text-column">13th Oct 23</td></tr>
<tr class=""><td class="last text-column">New 13102023</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">All</td><td class="last text-column">test test</td><td class="last text-column">13th Oct 23</td><td class="last text-column">13th Oct 23</td></tr>>
</tbody>
<tfoot>
<tr><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th><th class="last text-column"></th></tr>
</tfoot></table>
I tried it by creating custom keyword
@keyword
def read_table_data(self, locator):
# table = self.seleniumLib.get_webelement(locator)
headers=self.seleniumLib.get_webelements(locator+'/thead/tr[position()=1]/th/span')
column_headers=[]
for header in headers:
column_headers.append(self.seleniumLib.get_text(header))
data = []
rows = self.seleniumLib.get_webelements(locator+'/tbody/tr')
for row in rows:
row_data = []
columns =.self.selen iumLib.get_webelements('//td')
for column in columns:
row_data.append(self.seleniumLib.get_text(column))
data.append(row_data)
print(data)
Its fetching header sand rows properly but I am unable to fetch column inside each row wise.
I want to crate dataframe
out of this html
table