Back to Course
Java for Selenium

Conditions and loops

Conditions

if (age >= 18) {
    System.out.println("Adult");
} else {
    System.out.println("Minor");
}

Loops

for (int i = 0; i < 5; i++) { ... }
while (condition) { ... }
do { ... } while (condition);

Why Testers Use These Constantly

Loops are used to iterate over a list of WebElements (like all rows in a table), and conditions are used to branch logic based on page state (e.g., only click a button if it's visible).

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course