0
0
Selenium Pythontesting~10 mins

Reading test data from CSV in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to open the CSV file for reading.

Selenium Python
with open('testdata.csv', [1]) as file:
    reader = csv.reader(file)
    for row in reader:
        print(row)
Drag options to blanks, or click blank then click option'
A'x'
B'w'
C'r'
D'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' or 'a' mode which are for writing or appending, not reading.
2fill in blank
medium

Complete the code to import the module needed to read CSV files.

Selenium Python
[1]

with open('testdata.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        print(row)
Drag options to blanks, or click blank then click option'
Aimport os
Bimport csv
Cimport sys
Dimport json
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like os or json.
3fill in blank
hard

Fix the error in the code to read CSV data and print the first column of each row.

Selenium Python
with open('testdata.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        print(row[1])
Drag options to blanks, or click blank then click option'
A<0>
B(0)
C{0}
D[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or braces which cause syntax errors.
4fill in blank
hard

Fill both blanks to read CSV data into a list of dictionaries using DictReader.

Selenium Python
with open('testdata.csv', [1]) as file:
    reader = csv.[2](file)
    data = [row for row in reader]
    print(data)
Drag options to blanks, or click blank then click option'
A'r'
B'w'
Creader
DDictReader
Attempts:
3 left
💡 Hint
Common Mistakes
Using write mode or csv.reader instead of DictReader.
5fill in blank
hard

Fill all three blanks to read CSV data and assert the first row's 'username' is 'admin'.

Selenium Python
with open('testdata.csv', [1]) as file:
    reader = csv.DictReader(file)
    rows = list(reader)
    assert rows[[2]]['[3]'] == 'admin'
Drag options to blanks, or click blank then click option'
A'r'
B0
Cusername
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file mode, wrong index, or wrong dictionary key.