In Selenium testing using the Page Object Model, what is the main purpose of action methods defined in a page class?
Think about what actions a user can do on a web page and how tests simulate those.
Action methods encapsulate user interactions such as clicking buttons or entering text, making tests easier to read and maintain.
Given the following Java Selenium page class snippet, what will be the output when loginPage.login("user", "pass") is called?
public class LoginPage { WebDriver driver; public LoginPage(WebDriver driver) { this.driver = driver; } public void login(String username, String password) { System.out.println("Typing username: " + username); System.out.println("Typing password: " + password); System.out.println("Clicking login button"); } }
Look at the order of the print statements inside the login method.
The method prints the username first, then password, then clicking login button in that order.
Which locator strategy is best practice to use inside action methods in a page class for stable and maintainable tests?
Think about what locator is least likely to break when the page layout changes.
IDs or unique stable attributes provide the most reliable locators, making tests less fragile.
After calling an action method that submits a form, which assertion correctly verifies the success message text?
String expectedMessage = "Form submitted successfully!"; String actualMessage = driver.findElement(By.id("success-msg")).getText();
Check which assertion compares the expected and actual text exactly.
assertEquals verifies that the actual message matches the expected success message exactly.
An action method clickSubmit() in a page class throws ElementNotInteractableException during test runs. What is the most likely cause?
public void clickSubmit() {
WebElement submitBtn = driver.findElement(By.id("submit"));
submitBtn.click();
}ElementNotInteractableException means the element exists but cannot be clicked.
This exception usually means the element is present but hidden, disabled, or overlapped, so Selenium cannot interact with it.