Time to put it all together. You're going to write a complete login automation script from scratch. Open the Banking Portal, enter credentials, click Sign In, and verify the login worked. This is the exact kind of exercise you'll get in automation interviews.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class BankingLoginTest {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
try {
// Navigate to login page
driver.get("https://www.testerrank.com/banking/login");
System.out.println("Opened: " + driver.getTitle());
// Enter User ID
WebElement userId = driver.findElement(
By.cssSelector("[data-testid='userId']"));
userId.clear();
userId.sendKeys("rahul@netbank.com");
// Enter Password
WebElement password = driver.findElement(
By.cssSelector("[data-testid='password']"));
password.clear();
password.sendKeys("Bank@123");
// Click Sign In
driver.findElement(
By.cssSelector("[data-testid='loginBtn']")).click();
// Wait for page to load (we'll learn proper waits later)
Thread.sleep(2000);
// Verify login
String url = driver.getCurrentUrl();
if (url.contains("/banking/dashboard")) {
System.out.println("PASS — Login successful!");
// Read welcome message
WebElement welcome = driver.findElement(
By.cssSelector("[data-testid='welcomeUser']"));
System.out.println("Welcome: " + welcome.getText());
// Read account balance
WebElement balance = driver.findElement(
By.cssSelector("[data-testid='accBal1']"));
System.out.println("Balance: " + balance.getText());
} else {
System.out.println("FAIL — Not on dashboard");
// Check for error message
java.util.List<WebElement> errors = driver.findElements(
By.cssSelector("[data-testid='errorMsg']"));
if (!errors.isEmpty()) {
System.out.println("Error: " + errors.get(0).getText());
}
}
} catch (Exception e) {
System.out.println("FAIL — Exception: " + e.getMessage());
} finally {
driver.quit();
}
}
}Now try this on your own: go to the Shopping Portal catalog (/shopping/catalog), search for a product, filter by category, and add an item to the cart. Use what you learned about findElement, sendKeys, click, and getText.
Notice how we used data-testid attributes for all locators. In real projects, ask your developers to add data-testid attributes to critical elements. They're the most stable locators — they don't change when CSS classes or HTML structure changes.
Key Point: You just automated your first login flow. This exact pattern — navigate, find elements, interact, verify — is the foundation of every test you'll ever write.