2

Is there any python script to read data from excel sheet in selenium python framework?

I have written below code but i don't think its completely right

def getcell(rows,cols):

table=list()
record=list()

for x in range(rows):
    for y in range(cols):
        record.append(SheetName.cell(x,y).value)    
        table.append(record)
        record=[]
        rows=rows+1

return table;

print(table)

2
  • I don't think that this question is related to Selenium in any way (it my may merely be indirectly related to test automation). Please edit the question and the tags accordingly. Thanks. Commented Mar 25, 2018 at 20:13
  • Have you try pandas ? It seems like natural in order to treat your problem ? Commented Mar 26, 2018 at 17:15

1 Answer 1

3

try xrld. A python module used to read ms excel sheets. Here is a simple example provided in its readme file

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
for rx in range(sh.nrows):
    print sh.row(rx)
Sign up to request clarification or add additional context in comments.

3 Comments

hi And3r50n 1, it worked. I have one doubt, can we write code where in there is an excel sheet and we have to read multiple rows using tc id's.for ex: I have to read 1 row by passing an argument tc01.
yes it will. go ahead and embed the module in program . Please accept the answer and up vote it if it solved your problem
so can you please help me to write read multiple rows using tc id's script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.