DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

How to Automate React Applications with Selenium

Use Selenium to test a React app through its rendered browser interface, with setup guidance, reliable waits, and local-to-Grid execution advice.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To automate a React application with Selenium, drive it through a real browser as a user would, then wait for observable interface states—not merely for the page navigation to finish. Selenium controls the browser through WebDriver; React renders the interface into the browser DOM. You generally do not need access to React components or their internal state.

What Selenium does—and what it does not do

Selenium WebDriver drives a browser locally or on a remote machine through browser automation APIs; the WebDriver standard is a W3C Recommendation. React’s client APIs render the interface into a browser DOM node, which is what Selenium can locate and interact with. See Selenium’s WebDriver overview and React’s client React DOM API reference.

That makes Selenium suitable for end-to-end checks of visible behavior: entering text, clicking controls, following routes, and checking results or error messages. It is not a React component-testing tool. Keep tests focused on the browser-visible outcome rather than assuming access to component internals.

Install Selenium and create a browser session

The examples below use Selenium’s JavaScript bindings in a Node.js project. Install the package with npm, then create a WebDriver session, open your app, and quit the browser in a finally block so it closes even when a command or assertion fails.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm install selenium-webdriver

The Selenium JavaScript API page currently states a Node.js requirement of 22 or newer. Its listed support policy and browser details can change, so check the current JavaScript API documentation when setting up or upgrading. The page also documents Selenium Manager’s browser-driver handling.

const { Builder, Browser, By, until } = require('selenium-webdriver');

async function main() {
  const driver = await new Builder().forBrowser(Browser.CHROME).build();

  try {
    await driver.get('http://localhost:3000');
    console.log(await driver.getTitle());

    const saveButton = await driver.findElement(By.css('[data-testid="save"]'));
    await saveButton.click();

    const status = await driver.findElement(By.css('[role="status"]'));
    await driver.wait(until.elementIsVisible(status), 5000);
    console.log(await status.getText());
  } finally {
    await driver.quit();
  }
}

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

This is an illustrative pattern, not code verified against a particular application. Replace the URL and selectors with elements in your app, and choose a timeout suitable for your app and CI environment. The Selenium quick start demonstrates the session, navigation, title, and cleanup lifecycle; its wait documentation demonstrates explicit condition waits. It does not prescribe these selectors, timeout, or an assertion. See the JavaScript API and waiting strategies.

Choose locators that reflect your interface

Use selectors that identify the control or result the test needs to interact with. For example, a test could use an application-provided test attribute, an accessible role, or another stable selector. The right choice depends on the app; neither React nor Selenium requires the example’s data-testid attribute.

Prefer a locator that remains meaningful when layout or styling changes. Avoid tying a test unnecessarily to fragile details such as long chains of nested elements. If a control or result is not present yet because the app is rendering, synchronize on its expected state rather than repeatedly issuing immediate lookups.

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

Wait for React’s UI state after actions

A successful navigation does not guarantee that a React-driven update is complete. Selenium’s navigation wait targets a document readyState (by default, complete); that state concerns document assets, while JavaScript can still change the page afterward. A result element may be added or revealed only after an asynchronous request or user action. Selenium describes synchronization as a common browser-automation challenge in its waiting-strategies documentation.

Use condition-specific explicit waits

An explicit wait polls for a particular condition until it becomes true or the timeout expires. After clicking Save, for example, wait for the confirmation or updated content that proves the behavior under test. Selenium’s JavaScript API includes conditions such as until.elementIsVisible.

const message = await driver.findElement(By.css('[role="status"]'));
await driver.wait(until.elementIsVisible(message), 5000);
const text = await message.getText();

The example’s five-second timeout is illustrative, not a universal recommendation. Set a limit appropriate to the app and execution environment; when a wait fails, report which expected condition did not arrive. Selenium allows wait timeouts, polling intervals, ignored exceptions, and timeout messages to be configured.

Do not mix implicit and explicit waits

An implicit wait is a global setting for element-location commands. An explicit wait describes the condition needed at a particular point. Selenium warns that combining them can produce unpredictable timing. For React transitions, condition-specific explicit waits make the synchronization requirement clearer; avoid setting an implicit wait alongside them.

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

Fixed sleeps are a poor substitute for a condition: a delay that is too short can fail on a slower run, while a longer one wastes time when the UI is ready sooner. Wait for the state the next action or assertion actually needs.

Run locally first, then use remote execution when needed

For development, a locally served React app and a local browser are a straightforward place to begin. Selenium’s JavaScript API shows choosing a browser with Builder; it also documents remote sessions using usingServer(...) and the SELENIUM_REMOTE_URL environment variable. Consult the API documentation for the current configuration details.

Move to remote execution when tests need a different machine or browser environment. Selenium Grid is intended to run tests across multiple machines and platforms; it is not a prerequisite for a first local script. Selenium’s overview explains the roles of WebDriver and Grid. The documentation cited here does not establish a general cost or speed advantage for either arrangement.

Arrangement Browser location Useful when Responsibility to plan for
Local WebDriver session On the developer or test machine Building and debugging a test on a particular local setup That machine’s browser and test environment
Remote WebDriver session At the configured remote Selenium server The browser should run away from the test process Remote server configuration and availability
Selenium Grid Across Grid machines and platforms Broader machine or platform coverage Grid setup and the environments the team chooses to run

This is a functional distinction, not a performance or price comparison; those depend on the team’s infrastructure and are not established by the Selenium documentation cited here.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make failures useful to diagnose

When a browser test fails, identify whether it failed to find a control, to observe a UI transition, or to complete the browser session. A failure message that names the expected state is more actionable than a generic timeout.

  • Element not found immediately after navigation: the client-rendered interface may not have added it yet. Wait for the element or another specific condition before interacting.
  • Click completed but the expected result is absent: verify the test is waiting for the outcome of that action, and check that the chosen selector matches the rendered result.
  • Intermittent timeout: replace fixed delays or immediate lookups with a wait for the required condition. Review whether the timeout is suitable for the app and CI environment.
  • Unexpectedly long or inconsistent waits: check whether implicit and explicit waits are both configured; Selenium cautions against combining them.
  • Browser session does not close after an error: put cleanup in finally and call driver.quit().
  • Remote session cannot connect: check the configured Selenium server URL and remote service availability; use the API documentation’s remote-session configuration as the reference.

Or skip the browser setup

If your goal is to capture what a React page renders rather than exercise it with browser interactions, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return a PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets by default; those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.

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

See the ScreenshotNeo API documentation for authentication and request options. Selenium remains the fit when you need to click through the interface, submit forms, and verify behavior; a screenshot call captures a rendered page rather than replacing those interaction tests. ScreenshotNeo offers 1,000 screenshots per month free with no card, and paid plans start at $5 for 3,000. Sign up for free ScreenshotNeo access.

Frequently Asked Questions

Does Selenium need to know that an application uses React?

No. Selenium interacts with the browser and rendered DOM; it does not require React-specific component access.

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

Can I use Selenium for a screenshot instead of an interaction test?

Yes, Selenium controls a real browser, but a screenshot API may be simpler when you only need a rendered-page capture. ScreenshotNeo is one option for that workflow.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.