0
0
Selenium Pythontesting~20 mins

Reading test data from Excel in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Excel Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Excel data reading code?
Given the following Python code snippet using openpyxl to read an Excel file, what will be printed?
Selenium Python
from openpyxl import load_workbook
wb = load_workbook('testdata.xlsx')
sheet = wb.active
value = sheet['B2'].value
print(value)
ARaises KeyError
BNone
CRaises FileNotFoundError
DThe value in cell B2 of the Excel sheet
Attempts:
2 left
💡 Hint
Check if the file exists and the cell B2 has data.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the Excel cell value?
You read a value from Excel cell A1 into variable 'cell_value'. Which assertion correctly checks it equals 'TestUser'?
Selenium Python
cell_value = sheet['A1'].value
Aassert cell_value is 'TestUser'
Bassert cell_value = 'TestUser'
Cassert cell_value == 'TestUser'
Dassert cell_value != 'TestUser'
Attempts:
2 left
💡 Hint
Use double equals for comparison in assertions.
locator
advanced
2:00remaining
Choose the best locator to find a cell value in Selenium after reading from Excel
You read a username from Excel and want to find the input box on a web page to enter it. Which locator is best practice?
Adriver.find_element(By.CSS_SELECTOR, 'input[type=text]')
Bdriver.find_element(By.ID, 'username')
Cdriver.find_element(By.XPATH, '//input[@name="user"]')
Ddriver.find_element(By.TAG_NAME, 'input')
Attempts:
2 left
💡 Hint
Use unique and stable locators.
🔧 Debug
advanced
2:00remaining
Identify the error in this Excel reading code snippet
What error will this code raise?
Selenium Python
from openpyxl import load_workbook
wb = load_workbook('data.xlsx')
value = wb['Sheet1']['A1']
print(value.value)
ANo error, prints the cell value
BTypeError: 'Workbook' object is not subscriptable
CKeyError: 'Sheet1'
DAttributeError: 'Cell' object has no attribute 'value'
Attempts:
2 left
💡 Hint
Check how to access sheets in openpyxl.
framework
expert
2:30remaining
Which test framework feature best supports reading Excel data for multiple test cases?
You want to run a Selenium test multiple times with different data from Excel. Which pytest feature helps best?
A@pytest.mark.parametrize decorator with data loaded from Excel
BUsing unittest.TestCase with setUp method reading Excel once
CUsing pytest fixtures to read Excel data once per session
DHardcoding data inside the test function
Attempts:
2 left
💡 Hint
Think about running tests multiple times with different inputs.