Important Selenium Methods: From Legacy RC to W3C WebDriver

Browser automation frameworks have evolved dramatically from the early JavaScript-injected proxy architecture of Selenium RC (Remote Control, popularized in PHPUnit test suites) to the native browser control protocols of Selenium WebDriver (W3C WebDriver specification) and modern CDP/BiDi engines like Playwright. When maintaining legacy end-to-end test suites or migrating older PHPUnit Selenium tests to modern pipelines, engineers frequently need an authoritative reference mapping classic Selenium RC setup, action, query, and assertion methods to their modern counterparts.

Architectural Shift: Selenium RC vs. W3C WebDriver

In Selenium 1.x (Selenium RC), the test runner communicated with a standalone Java proxy server that injected a JavaScript automation harness (Selenium Core) directly into the browser frame. Every command—such as open(), click(), or waitForPageToLoad()—executed inside the browser's JavaScript sandbox, which introduced same-origin policy restrictions and synthetic event quirks.

Modern Selenium WebDriver (Selenium 4+) eliminates the JavaScript proxy entirely, communicating directly with native browser drivers (chromedriver, geckodriver) over the W3C WebDriver wire protocol and WebDriver BiDi. Explicit condition polling replaces brittle full-page wait calls.

Session Setup and Configuration Methods

In legacy PHPUnit Selenium RC suites, session parameters were configured via setter methods inside the setUp() lifecycle hook before invoking start(). In modern WebDriver, these settings are encapsulated inside browser capability options and timeout configurations.

Legacy Selenium RC Method Responsibility Selenium 4 WebDriver Equivalent
setBrowser($browser) Selects target browser engine (e.g., Firefox or Chrome). new Builder().forBrowser(Browser.CHROME)
setBrowserUrl($url) Configures base origin URL for relative navigation paths. Managed via test runner config or base URL helper
setHost($host) / setPort($port) Points client to remote Selenium Grid hub endpoint. usingServer('http://grid-host:4444/wd/hub')
setTimeout($timeout) Sets global command execution timeout threshold. driver.manage().setTimeouts({ pageLoad, implicit })

Browser Navigation and DOM Action Methods

Action methods drive user interactions across the Document Object Model (DOM), including navigation, mouse clicks, keyboard input, form controls, and dialog handling.

Legacy Selenium RC Action Behavior Summary Modern WebDriver / Playwright Pattern
open($url) Navigates active browser frame to target URL. await driver.get(url) / page.goto(url)
goBack() / refresh() / close() Triggers history back, page reload, or tab closure. driver.navigate().back(), refresh(), driver.close()
click($locator) Dispatches click on link, button, radio, or checkbox. await driver.findElement(By.css(sel)).click()
clickAndWait($locator) Clicks target element and blocks until navigation completes. Click followed by driver.wait(until.urlContains(...))
type($locator, $value) Populates text input or textarea field with string value. element.clear() + element.sendKeys(value)
select($selectLoc, $optLoc) Chooses an option inside a native <select> dropdown. new Select(element).selectByVisibleText(label)
check($loc) / uncheck($loc) Toggles boolean state of checkbox or radio input. Inspect isSelected() before calling click()
mouseOver($loc) / keyPress($loc, $key) Simulates pointer hover or keyboard press sequence. driver.actions().move({ origin: el }).perform()
selectWindow($windowId) Switches execution context to popup window or tab handle. driver.switchTo().window(windowHandle)
chooseCancelOnNextConfirmation() Dismisses upcoming native window.confirm() dialog. await driver.switchTo().alert().dismiss()
waitForCondition($script, $timeout) Polls custom JS expression until truthy or timeout expires. await driver.wait(until.elementLocated(...), ms)

DOM State Queries and Element Inspection

Instead of querying the DOM through string-based locator functions on the root client object, modern WebDriver scopes state inspection methods directly to resolved WebElement instances and WebDriver getters.

Legacy Query Method Returned Data Modern WebDriver Equivalent
getTitle() / getLocation() Current document title string or absolute URL. driver.getTitle() / driver.getCurrentUrl()
getText($locator) Rendered visible inner text of matching DOM node. element.getText()
getValue($locator) Current value property of form input control. element.getAttribute('value')
getElementAttribute($attrLoc) Attribute string from target DOM node. element.getAttribute(attrName)
isElementPresent($locator) Boolean indicating whether selector matches any node in DOM. (await driver.findElements(By.css(sel))).length > 0
isVisible($locator) Boolean checking layout visibility (non-zero box, not hidden). await element.isDisplayed()
isEditable($locator) Boolean verifying input is enabled and not read-only. await element.isEnabled()
getEval($script) Return value of synchronous JavaScript execution in page. await driver.executeScript(script, ...args)

Assertions and Explicit Waits in Modern TypeScript Suites

Legacy PHPUnit Selenium bundled assertion helpers like assertElementPresent(), assertTextPresent(), assertElementValueEquals(), and assertVisible() directly into the test case base class. Because those assertions executed synchronously without automatic retry polling, single-page applications (SPAs) frequently suffered from flaky race conditions when asynchronous network requests delayed DOM rendering.

In modern Selenium 4 (TypeScript/Node.js), always pair explicit waits (driver.wait with until conditions) with DOM locators before asserting state:

import { Builder, By, until, WebDriver } from 'selenium-webdriver';
import assert from 'node:assert/strict';

export async function verifyCheckoutSubmission(driver: WebDriver): Promise<void> {
  await driver.get('https://example.com/checkout');

  // Replace legacy type() + clickAndWait() with explicit locator waits
  const emailInput = await driver.wait(
    until.elementLocated(By.css('input[name="customer_email"]')),
    5000
  );
  await emailInput.clear();
  await emailInput.sendKeys('architect@webdesigner.la');

  const submitButton = await driver.findElement(By.css('button[type="submit"]'));
  assert.equal(await submitButton.isEnabled(), true, 'Submit button must be enabled');
  await submitButton.click();

  // Replace legacy waitForPageToLoad() + assertTextPresent() with condition polling
  const confirmationBanner = await driver.wait(
    until.elementLocated(By.css('[data-testid="order-confirmed"]')),
    10000
  );
  await driver.wait(until.elementIsVisible(confirmationBanner), 5000);

  const bannerText = await confirmationBanner.getText();
  assert.match(bannerText, /Order Confirmed/i);
}

Key Migration Takeaways

  • Eliminate Implicit and Fixed Sleeps: Replace waitForPageToLoad() and fixed timeouts with deterministic driver.wait(until.elementIsVisible(...)) predicates.
  • Use Resilient DOM Locators: Prefer semantic attributes (data-testid, ARIA roles, or stable CSS selectors) over brittle XPath indices or auto-generated IDs.
  • Decouple Driver Transport from Assertions: Keep WebDriver responsible for browser queries and delegate test assertions to native assertion libraries or auto-retrying expect matchers.