Unit 2: Selenium IDE and WebDriver
I. Orientation
Selenium is an open-source suite for automating web browsers. Originating as a browser-testing tool at ThoughtWorks in 2004, Selenium now supports record-and-playback testing through Selenium IDE and programmable browser automation through Selenium WebDriver.
Defining characteristics:
- Browser-based automation: Selenium interacts with web applications through real browsers, allowing tests to reproduce actions such as clicking links, entering text, and navigating between pages.
- Two automation approaches:
- Selenium IDE provides a graphical environment for recording and replaying tests with little or no programming.
- Selenium WebDriver provides language APIs for writing maintainable automation programs.
- Element identification: Commands act on page elements located by identifiers such as
id,name, CSS selectors, link text, and XPath. - Client-side scope: Selenium automates browser-visible behavior; it does not directly test databases, server internals, or native desktop applications.
- Testing objective: A Selenium test combines actions with assertions so that it verifies behavior instead of merely repeating browser operations.
- Synchronization requirement: Modern pages load asynchronously, so reliable tests must wait for required conditions rather than assume that every element is immediately available.
II. Selenium IDE — Record-and-Playback Automation
A. Introduction to Selenium IDE
Selenium IDE is a browser extension that records, edits, executes, and exports browser automation tests through a graphical interface.
- Availability: Selenium IDE is commonly installed as an extension for browsers such as Chrome, Firefox, and Edge.
- Project structure: An IDE project can contain multiple test cases and test suites.
- A test case is one sequence of commands for a particular scenario.
- A test suite groups related test cases for combined execution.
- Command model: Each test step generally contains:
- Command: The operation, such as
clickortype. - Target: The element locator or destination URL.
- Value: Optional input or expected content.
- Command: The operation, such as
- Selenese: The command vocabulary historically used by Selenium IDE is called Selenese. A row such as
type | id=email | learner@example.comenters text into the element whoseidisemail. - Main purpose: The IDE is useful for learning Selenium, rapidly creating prototypes, reproducing defects, and automating small or straightforward workflows.
- Test oracle: Verification commands provide the expected result. Without an assertion such as
assertText, a successful replay only proves that Selenium completed the actions. - Limitations: Large test systems usually require WebDriver code because recorded tests can become repetitive, fragile, and difficult to organize around reusable components.
B. Features of Selenium IDE
Selenium IDE combines recording facilities with editing, execution, inspection, and test-organization tools.
- Record and playback: User actions are translated into editable commands and can be replayed in the browser.
- Automatic locator generation: The recorder captures one or more possible locators for an element, commonly using
id, CSS, XPath, or link text. - Command editor: Commands, targets, and values can be inserted, removed, reordered, copied, or modified after recording.
- Assertions and verification: Commands can check page titles, text, element presence, values, and other observable conditions.
- An assert command stops the current test when its condition fails.
- A verify command reports failure but normally allows subsequent steps to run.
- Test suites: Related login, search, checkout, or account tests can be collected and executed together.
- Control flow: Supported IDE versions provide commands such as
if,else,while, andtimes, enabling conditional execution and repetition. - Variables: Commands such as
storeretain values for later use. A stored value can be referenced with syntax such as${username}. - Debugging tools: Breakpoints, start points, step execution, logs, and command highlighting help isolate failures.
- Run controls: Tests may be run individually or as suites, and playback speed can be adjusted when examining behavior.
- Code export: Recorded tests can be exported to supported WebDriver language and framework formats, although exported code generally requires refactoring.
- Command-line execution: Selenium IDE projects can be run through compatible command-line tooling, making limited automated or continuous-integration execution possible.
C. Creating a script by recording
Recording creates an initial test by translating browser interactions into Selenium IDE command rows.
- Preparation: Install Selenium IDE, create a project, enter the application’s base URL, and give the first test a meaningful name.
- Recording process:
- Start recording and allow the IDE to open the base URL.
- Perform only the actions required by the scenario.
- Add assertions for important outcomes.
- Stop recording, review the generated commands, and save the project.
- Recorded actions: Opening a page, clicking a button, selecting an option, and entering text may produce commands such as:
open /login
type id=email learner@example.com
type id=password examplePassword
click css=button[type="submit"]
assertText css=h1 Dashboard- Locator review: Generated locators should be checked for stability.
id=login-buttonis generally more maintainable than an absolute XPath such as/html/body/div[2]/form/button. - Assertion insertion: Assertions may need to be added manually because recording actions alone does not establish the expected result.
- Sensitive data: Real passwords, access tokens, and personal information should not be stored directly in recorded project files.
- Replay and refinement: Run the test from its beginning, inspect failures, remove unnecessary commands, and replace unstable locators.
- Worked example: In the login sequence above,
assertText | css=h1 | Dashboardmakes the test fail if the expected heading is absent, distinguishing a valid login from a merely completed click.
D. Introduction to Selenium IDE Commands
Selenium IDE commands specify the action to perform, the target on which it operates, and any supporting value.
- Action commands: These modify browser state or interact with the page.
openloads a relative or absolute URL.clickactivates an element.typereplaces the contents of an input field.selectchooses an option from a list.sendKeyssends keyboard input to an element.
- Assertion commands: Commands such as
assertTitle,assertText, andassertElementPresentstop the test when the expected condition is false. - Verification commands: Commands such as
verifyTextrecord a mismatch while permitting the test to continue, which can reveal multiple defects in one run. - Wait commands: A command such as
waitForElementVisibledelays the next step until its condition becomes true or the timeout expires. - Storage commands:
store,storeText, and related commands place data in variables for later commands. - Locator syntax: Targets may use forms such as
id=search,name=query,css=.result-title,xpath=//button[@type='submit'], orlinkText=Sign in. - Command interpretation: In
type | id=email | user@example.com,typeis the operation,id=emailidentifies the input, anduser@example.comis the supplied value. - Reliability principle: Condition-based waits are preferable to fixed pauses because page response time varies between machines and network conditions.
III. Selenium IDE Debugging — Controlled Test Diagnosis
A. Debugging in Selenium IDE using Breakpoint and Start Point Methods
Breakpoints and start points control where execution pauses or begins, making failed command sequences easier to inspect.
-
Breakpoint method:
- Purpose: A breakpoint pauses execution immediately before a selected command.
- Use: Set a breakpoint on or near the suspected failing step, run the test, and inspect the page when execution pauses.
- Diagnosis: The tester can check whether a modal blocks the target, a locator matches the wrong element, or expected data is missing.
- Continuation: After pausing, execute commands step by step or resume normal playback.
- Example: A breakpoint before
click | id=submit-orderallows inspection of whether the button is visible and enabled.
-
Start point method:
- Purpose: A start point begins playback from a selected command instead of the first command.
- Use: Manually prepare any required application state, mark the relevant command as the start point, and run the remaining sequence.
- Efficiency: This avoids repeatedly executing lengthy setup steps while investigating a later section.
- Constraint: Earlier commands may create sessions, variables, or page state. Skipping them can cause misleading failures if those prerequisites are not reproduced.
- Explicit contrast: A breakpoint controls where an otherwise normal run pauses, whereas a start point controls where the run begins.
- Supporting evidence: Selenium IDE logs show executed commands, status, and error information; the highlighted row identifies the current or failed command.
- Debugging discipline: After correcting the issue, remove temporary execution controls and run the complete test from the beginning to confirm that setup and dependencies remain valid.
IV. Selenium WebDriver — Programmable Browser Control
A. Selenium Browser Automation using WebDriver
Selenium WebDriver is a programming interface that controls browsers using browser-specific automation mechanisms and the W3C WebDriver standard.
- Architecture: Test code sends WebDriver commands to the browser’s automation endpoint, which performs operations and returns results.
- Language bindings: Selenium provides APIs for languages including Java, Python, JavaScript, C#, and Ruby.
- Driver creation: A browser session begins by constructing a driver object. Modern Selenium installations can often manage compatible driver binaries automatically.
- Element interaction:
findElementlocates an element; methods such asclick,sendKeys, andgetTextoperate on it. - Java example:
WebDriver driver = new ChromeDriver();
driver.get("https://example.com/login");
driver.findElement(By.id("email")).sendKeys("learner@example.com");
driver.findElement(By.cssSelector("button[type='submit']")).click();
driver.quit();- Session cleanup:
quit()closes every window in the WebDriver session and releases associated browser resources. - Synchronization: Explicit waits monitor conditions such as visibility, clickability, or URL changes. They are more dependable than fixed delays such as
Thread.sleep. - Maintainability: WebDriver supports reusable methods, test data, page objects, reporting, and integration with frameworks such as JUnit, TestNG, NUnit, and pytest.
B. Types of Browser Support for Selenium WebDriver
WebDriver supports major desktop browsers through browser-specific driver implementations and capabilities.
- Google Chrome: ChromeDriver controls Chromium-based Chrome sessions.
- Mozilla Firefox: GeckoDriver connects Selenium with Firefox.
- Microsoft Edge: EdgeDriver controls the Chromium-based Edge browser.
- Apple Safari: SafariDriver is supplied with Safari on supported macOS systems and must be enabled for automation.
- Chromium browsers: Selenium can automate compatible Chromium-based browsers when the appropriate binary and options are configured.
- Browser options: Capabilities configure headless execution, download behavior, profiles, proxies, certificates, window size, and other session properties.
- Version compatibility: The browser, driver, Selenium library, and operating environment must be compatible; automated driver management reduces manual matching problems.
- Local execution: The driver and browser run on the same machine as the test process.
- Remote execution: Remote WebDriver or Selenium Grid runs tests on other machines, browsers, operating systems, or containerized nodes.
- Cross-browser significance: Running the same behavioral test on Chrome, Firefox, Edge, and Safari can expose differences in rendering, JavaScript behavior, and browser-specific features.
C. Browser Navigation Commands in Selenium
Navigation commands move through browser history, load URLs, and refresh the current document.
- Direct navigation:
driver.get(url)loads a URL and is commonly used for initial page access.
driver.get("https://example.com");- Navigate-to operation:
driver.navigate().to(url)also loads a destination and belongs to WebDriver’s navigation interface.
driver.navigate().to("https://example.com/products");- Backward navigation:
driver.navigate().back()behaves like the browser’s Back button and moves to the previous history entry. - Forward navigation:
driver.navigate().forward()moves to the next history entry after backward navigation. - Refresh operation:
driver.navigate().refresh()reloads the current page, which is useful when checking updated server or client state. - Current location:
driver.getCurrentUrl()returns the active URL for comparison with the expected destination. - History condition:
back()andforward()depend on available browser history; they cannot move where no corresponding history entry exists. - Timing consideration: Navigation may trigger asynchronous rendering after the initial document load, so an explicit wait should verify the required page condition before interaction.
- Window distinction: Navigation commands operate within the current window or tab. Switching to another tab requires an explicit window-handle operation before navigation continues there.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →