Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read Excel File by Selenium in DDT

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to read the Excel file in Selenium in DDT, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

(1) install xlrd pip3 install xlrd

(2) sample script

Import pytest import xlrd def get_data (): filename= "F:\\ Learning\\ Automation Test\\ selenium Automation Test\\ selenium_test\\ data\\ test.xls" # read Workbook wb=xlrd.open_workbook (filename) # read first sheet Page sheet=wb.sheet_by_index (0) # read Line rows=sheet.nrows # read column cols=sheet.ncols Lst= [] for row in range (rows): for col in range (cols): # get cell data cell_data=sheet.cell_value (row) based on rows and rows Col) lst.append (cell_data) return lst@pytest.mark.parametrize ('name',get_data ()) def test1 (name): print (name) if _ _ name__ =' _ _ main__': pytest.main (['- sv','test.xls'])

Running result:

[FAQ]: error running test footer.

It turns out that the reason is that xlrd has recently been updated to version 2.0.1, and only .xls files are supported.

[solution]:

(1) use xls files in scripts

(2) you can install the old version of xlrd and run it in cmd:

Pip3 uninstall xlrd

Pip3 install xlrd==1.2.0

This is the answer to the question about how Selenium reads Excel files in DDT. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report