Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Selenium Python - Data-Driven Testing
Identify the error in this code snippet:
from openpyxl import load_workbook
wb = load_workbook('data.xlsx')
sheet = wb['Sheet1']
value = sheet.cell(row=0, column=1).value
print(value)
Aload_workbook cannot open .xlsx files
BSheet name should be 'sheet1' lowercase
CRow index starts at 1, not 0
Dcell() method requires string coordinates
Step-by-Step Solution
Solution:
  1. Step 1: Check row and column indexing

    openpyxl uses 1-based indexing for rows and columns; row=0 is invalid.
  2. Step 2: Verify sheet access and method usage

    Sheet name 'Sheet1' is case-sensitive but usually correct; cell() accepts numeric indices.
  3. Final Answer:

    Row index starts at 1, not 0 -> Option C
  4. Quick Check:

    Row indexing starts at 1 [OK]
Quick Trick: Row and column indexes start at 1 in openpyxl [OK]
Common Mistakes:
  • Using zero-based row or column index
  • Assuming sheet names are case-insensitive
  • Thinking cell() needs string like 'A1'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes