Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a Page Object Model (POM) to keep Selenium selectors and browser interactions in JavaScript page classes, while tests describe user flows and own their assertions. The JavaScript binding is the selenium-webdriver package; Selenium’s official POM guidance explains the design principles, though its examples are primarily in Java.

What the Page Object Model does

A page object represents a web page—or a meaningful region of one—as an object that exposes user-facing operations. It keeps details such as selectors and click or typing sequences out of individual tests. When the UI changes, you can often update the relevant page object instead of editing every test that used the old selector. Selenium’s Page Object Model guidance describes this separation.

A test should read like a scenario: open the login page, sign in, then check the result. The page object handles how to perform those actions. The test decides whether the observed result meets the scenario’s expectation.

Install Selenium and prepare Node.js

The Selenium JavaScript API reference specifies Node.js 22 or later and documents installation with npm install selenium-webdriver. The support dates published in the API reference accessed October 3, 2026 are Node.js 22 through April 30, 2027; Node.js 24 through April 30, 2028; and Node.js 26 through April 30, 2029. Runtime support policies can change, so check the current Selenium JavaScript API reference when choosing a Node release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. Install a supported Node.js release and create or enter your test project.
  2. Run npm install selenium-webdriver.
  3. Use a browser supported by your Selenium setup. Selenium Manager can automatically handle browser-driver installation in the documented local setup.

Build page objects around actions and outcomes

This illustrative JavaScript adaptation applies Selenium’s documented design principles; selectors and expected text are examples, not application-specific values. Save it in a file such as pages.js:

const { By } = require('selenium-webdriver')

class LoginPage {
  constructor(driver) {
    this.driver = driver
    this.username = By.name('username')
    this.password = By.name('password')
    this.submit = By.css('button[type="submit"]')
  }

  async open() {
    await this.driver.get('https://example.test/login')
  }

  async signIn(username, password) {
    await this.driver.findElement(this.username).sendKeys(username)
    await this.driver.findElement(this.password).sendKeys(password)
    await this.driver.findElement(this.submit).click()
    return new HomePage(this.driver)
  }
}

class HomePage {
  constructor(driver) {
    this.driver = driver
    this.heading = By.css('h1')
  }

  async headingText() {
    return this.driver.findElement(this.heading).getText()
  }
}

module.exports = { LoginPage, HomePage }

The page object stores locators and provides operations such as open and signIn. Since signing in moves to another page, signIn returns a HomePage object. Keeping this transition explicit makes the next step in a test clear.

Write a test that owns the assertion

The following is the test-flow shape; connect it to your chosen test runner and its assertion library. The test controls the driver lifecycle and checks the expected outcome rather than hiding that expectation inside a page method.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
const assert = require('node:assert/strict')
const { Builder } = require('selenium-webdriver')
const { LoginPage } = require('./pages')

async function run() {
  const driver = await new Builder().forBrowser('chrome').build()

  try {
    const login = new LoginPage(driver)
    await login.open()
    const home = await login.signIn('reader', 'example-password')
    assert.equal(await home.headingText(), 'Welcome')
  } finally {
    await driver.quit()
  }
}

run().catch((error) => {
  console.error(error)
  process.exitCode = 1
})

Replace the example URL, credentials, selectors, browser choice, and assertion with values appropriate to your app and test environment. Keep cleanup in finally so the browser session is closed when an operation or assertion fails.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose page, component, and assertion boundaries

Keep selectors and UI mechanics in page objects

Prefer signIn(username, password) to test code that independently finds username, password, and submit elements. A UI change then has a focused place to update. Expose useful observations such as headingText() when tests need them, rather than exposing every implementation detail.

Use component objects for meaningful repeated regions

A navigation bar, product card, or other repeated region can be modeled as a component object when that improves reuse or clarity. Selenium’s JavaScript binding lets you search beneath a WebElement, so a component can scope lookups to its root rather than searching the entire page. See the JavaScript WebElement API.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Keep scenario assertions in the test

Selenium’s documentation states: “Page objects themselves should never make verifications or assertions.” It also allows a narrow check during construction that the expected page, or a critical element, has loaded. Use such a check for page identity or readiness, not for scenario-specific outcomes such as whether a particular user should see a welcome message.

Represent different outcomes clearly

If an action can lead to distinct states, design methods and observations so the test can express which path it is taking. For example, a successful login may lead to a home page, while invalid credentials may leave the user on the login page with an error message. Avoid a method whose name implies success if it obscures whether success actually occurred.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run locally or against a remote Selenium server

For a local browser session, Selenium’s JavaScript API quick start uses Builder, selects a browser, navigates with driver.get, and quits the driver. Selenium Manager handles browser-driver installation in the documented setup.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

For a Selenium Grid or standalone remote server, configure the builder with usingServer. The API reference also documents the SELENIUM_REMOTE_URL environment variable for specifying the remote server. Remote execution moves the browser session to that server; your test still passes the resulting driver into page objects in the same way.

Practical workflow for adding POM to a test suite

  1. Choose one real user flow and list the actions and observations the test needs.
  2. Create a page object for each page with meaningful behavior, keeping that page’s selectors and interactions there.
  3. Pass the WebDriver into each page object so test setup remains responsible for the browser session.
  4. Return a new page object when an action navigates to a different page; return the same object or a component where that better matches the flow.
  5. Extract repeated regions into component objects only when doing so improves reuse or makes the model clearer.
  6. Keep scenario expectations and assertions in the test, with at most a narrow page-readiness check in the page object.
  7. Close the driver in a finally block and check Selenium’s current JavaScript API for runtime and browser setup requirements.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common POM problems

  • Driver setup fails before the page opens: Check that the installed Node.js version meets the current API requirement, the selected browser is available, and local browser-driver setup or the remote Selenium server is configured. Consult the current API reference for setup details.
  • A locator cannot find an element: Confirm the selector against the current application markup and ensure the page has reached the state where the element exists. Keep the selector in the page object so it can be corrected in one place.
  • A click or typing step fails intermittently: Check whether the UI has finished rendering or is showing a different state before interaction. Model the required readiness or state observation in the page API, and have the test use it before asserting the scenario outcome.
  • A test leaves browser sessions open: Put await driver.quit() in a finally block surrounding the flow, so cleanup still runs when a command or assertion throws.
  • A page object becomes a large grab bag: Split out a repeated or independently meaningful region as a component, or separate distinct pages. Avoid creating tiny objects solely to wrap a single selector when that makes the flow harder to follow.
  • Tests become difficult to understand: Replace raw selector access in test code with operations named for user intent, and keep expected results visible in the test’s assertions.

Or skip the browser setup

For capturing a page image or PDF without building a Selenium session, ScreenshotNeo accepts a URL in one request. Its API documentation describes the request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server lets AI agents use screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. These are screenshot and PDF capabilities, not a replacement for Selenium when you need to interact with an application and verify behavior through browser tests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Frequently Asked Questions

Can I use Page Objects with any JavaScript test runner?

Yes. Page objects are an organization pattern around WebDriver; the test runner supplies the test lifecycle and assertion tools.

Does Selenium’s Page Object Model documentation provide a JavaScript example?

Its canonical guidance illustrates the pattern primarily with Java. Apply the principles to Selenium’s JavaScript binding, as in the adaptation above.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.