Browser Navigation, Commands, Element Actions, and Basic Workflows
Control the browser, navigate across pages, and perform the basic actions used in almost every Selenium automation script.
Inside this chapter
- Basic Browser Operations
- Getting Page Information
- Common Element Actions
- Reading Element State
- Simple Workflow Example
- Why Cleanup Still Matters
Series navigation
Study the chapters in order for the clearest path from Selenium setup and locators to framework design, CI integration, flaky-test control, and advanced automation engineering practice. Use the navigation at the bottom to move smoothly through the full tutorial series.
Basic Browser Operations
driver.get("https://example.com");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
Navigation commands are simple but essential in many end-to-end user journeys.
Getting Page Information
String title = driver.getTitle();
String url = driver.getCurrentUrl();
These are often used in assertions and debugging.
Common Element Actions
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("secret");
driver.findElement(By.id("loginBtn")).click();
Selenium supports click, typing, clear, submit, and value extraction operations that form the core of most UI tests.
Reading Element State
WebElement button = driver.findElement(By.id("saveBtn"));
button.isDisplayed();
button.isEnabled();
button.isSelected();
Understanding element state helps testers build smarter assertions and avoid interacting with elements prematurely.
Simple Workflow Example
A login automation might open the app, enter credentials, click login, wait for dashboard presence, and verify the user menu appears. That simple flow already includes navigation, element identification, action sequencing, and validation.
Why Cleanup Still Matters
Even simple workflows should close or quit the browser correctly. Orphan browser sessions waste resources and can create confusion during larger test runs.