Selenium + Java · Lesson 2 of 44
Module 2: Conditional Statements & Loops
Your task
Implement evaluateStatusCode:
Write it in the editor, then press Check answer (Ctrl + Enter).
int statusCode = 200;
if (statusCode == 200) {
System.out.println("API Success");
} else if (statusCode == 404) {
System.out.println("Endpoint Not Found");
} else {
System.out.println("Unhandled error code: " + statusCode);
}// While loop retry pattern:
int attempts = 0;
boolean isElementReady = false;
while (attempts < 3 && !isElementReady) {
attempts++;
// poll element state
}In test automation, you constantly check HTTP status codes, retry failed locator checks, and iterate through table rows. In this lesson, you will master conditional branching and loop structures in Java. Let's dive in!
Part of the Selenium + Java course (Selenium with Java). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
Use switch statements when selecting browser engines (e.g., 'chromium', 'firefox', 'webkit') or running tests on specific environment flags.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___