我想读取整个行数据并将其存储在变量中,稍后在selenium中使用它们将其写入webelements。编程语言是Python。
示例:我有一张优秀的事故表及其有关优先权,日期,受让人等的详细信息
如果我将字符串作为INC00000,它应该与excel数据匹配,获取所有上述细节并将其存储在单独的变量中,如
INC #= INC0000 Priority= Moderate Date = 11/2/2020
这可行吗?我尝试编写代码失败了。请建议其他可能的方法。
答案 0 :(得分:0)
我愿意,
示例:
import pandas as pd
df = pd.read_excel("full_file_path", sheet_name="name_of_sheet")
dict_data = df[df['INC #']].to_dict("record") # <-- assuming the "INC #" are in column named "INC #" in the spreadsheet
webelement1.send_keys(dict_data[columnname1])
webelement2.send_keys(dict_data[columnname2])
webelement3.send_keys(dict_data[columnname3])
.
.
.
答案 1 :(得分:0)
在将excel文件另存为csv后,请找到以下代码并根据您的变量进行更改: Please find the dummy data image
import csv
# Set up input and output variables for the script
gTrack = open("file1.csv", "r")
# Set up CSV reader and process the header
csvReader = csv.reader(gTrack)
header = csvReader.next()
print header
id_index = header.index("id")
date_index = header.index("date ")
var1_index = header.index("var1")
var2_index = header.index("var2")
# # Make an empty list
cList = []
# Loop through the lines in the file and get required id
for row in csvReader:
id = row[id_index]
if(id == 'INC001') :
date = row[date_index]
var1 = row[var1_index]
var2 = row[var2_index]
cList.append([id,date,var1,var2])
# # Print the coordinate list
print cList