An automated login check must do more than open a page: it must find the login link, enter credentials, submit the form, and verify who logged in. In Selenium WebDriver, findElement() returns a WebElement representing one page element. That object is the handle used to interact with or inspect it. section 10.2.11
Choose a locator that identifies the intended element:
- Use an HTML id or name for a significant field or button when available. These attributes are less likely to change with page layout than a structural locator. section 10.2.12
- Use link text for a recognizable link, or a CSS selector or XPath expression when the element needs a more specific match. section 10.2.12
- Narrow a search to a containing WebElement when the same kind of element appears elsewhere on the page. section 10.2.12
Log in and check the result
After opening the application, driver.findElement(By.linkText("Login")).click() follows the login link. Locate the email and password fields by id and call sendKeys() on each; then locate and click the login button. To check the result, read the current-user element with getText() and compare it with the expected email address. section 10.2.11
A WebElement supports common user actions and checks: click() simulates a click, sendKeys() simulates typing, and getText() reads visible text content. Clear an existing text-field value before typing a replacement. To inspect a field’s current value, read its value attribute with getAttribute("value"). A select field can be passed to Selenium’s Select helper. section 10.2.13
Check a group of destinations
When a home page should show three featured destinations, findElements(By.cssSelector(".featured-destination")) returns a list of WebElement objects whose size can be checked. Find title elements under #featured, read each with getText(), and check that the resulting titles include Singapore. section 10.2.12
In Serenity/JS, the corresponding single-element abstraction is PageElement, not Selenium’s WebElement. A PageElement can be located with a By selector or described relative to a containing PageElement—useful when a repeated widget needs a specific message identified. section 15.2.2
