Playwright + Python · Lesson 2 of 37
Module 2: Conditional Statements & Loops
Your task
Implement find_index_of_target(items, target):
Write it in the editor, then press Check answer (Ctrl + Enter).
# Evaluating status codes:
status_code = 200
if status_code == 200:
print("API Success")
elif status_code == 404:
print("Endpoint not found")
else:
print(f"Unexpected status: {status_code}")
# Retry loop pattern:
max_retries = 3
for attempt in range(1, max_retries + 1):
print(f"Attempt {attempt} of {max_retries}")
# poll element stateIn automated tests, you often evaluate response status codes, retry failed assertions, and iterate through lists of table rows. In this lesson, you will master if, elif, else, while retry loops, and enumerate(). Let's dive into control flow!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
enumerate() is Pythonic and yields both the 0-based index and the item directly without requiring manual list indexing.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___