This test opens a login page, enters username and password, clicks the login button, and checks if the page title changes to 'Dashboard' to confirm success.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class ClickActionTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com/login");
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginBtn"));
username.sendKeys("testuser");
password.sendKeys("password123");
loginButton.click();
// Check if login was successful by checking page title
String title = driver.getTitle();
if (title.equals("Dashboard")) {
System.out.println("Test Passed: Login successful.");
} else {
System.out.println("Test Failed: Login unsuccessful.");
}
} finally {
driver.quit();
}
}
}