Form parameterization (CSV)
If I have an automated script to parameterize a form, the form needs to fill in the user name, mailbox, age, gender and other information, using the above method is difficult to solve the problem, the following method to read the CSV file to solve the problem.
Create a userinfo.csv file, 5.x
Figure 4.8
Create a table via WPS or Excel, save the file as select CSV format, modify the loop_reader.py file below to cycle read
Take:
#coding =utf-8
Import CSV #导入csv Package
#读取本地CSV file
My_file= ' D:\\selenium_python\\data\\userinfo.csv '
Data=csv.reader (File (my_file, ' RB '))
#循环输出每一行信息
For user in data:
Print User[0]
Print User[1]
Print User[2]
Print User[3]
Operation Result:
>>> ========================= RESTART ==============================
>>>
Testing
[Email protected]
23
Man
Testing2
[Email protected]
18
Woman
Testing3
[Email protected]
29
Woman
Csv.reader () is used to read the CSV file, User[0] represents the data (user name) of the first column in the table, User[0] represents the data (mailbox) of the second column in the table, and so on. It is more flexible to read files through CSV, which can iterate through each piece of data without limiting the number of data read each time.
Form parameterization (CSV)