---
title: Testing with React and Selenium | Testing Resources
description: How to test a React site with both React Testing Library and Selenium
  WebDriver, and when each of the two is the right tool to reach for.
source_url:
  html: https://testingbot.com/resources/articles/react-selenium-testing
  md: https://testingbot.com/resources/articles/react-selenium-testing.md
---

![Testing with React and Selenium](https://testingbot.com/assets/resources/articles/31.webp)

# React Testing with Selenium

How to test a React site with both React Testing Library and Selenium WebDriver, and when each of the two is the right tool to reach for.

By [Jochen D.](https://testingbot.com/about/jochen-d)2023-09-06Updated 2026-08-31

 Share on Facebook 

 Share on Twitter 

 Post on Reddit 

 Share link 

React is a JavaScript library which is developed by Facebook. Meta used React to build the Instagram.com website. One of the advantages of using React is that it allows frontend and web developers to quickly create user interfaces (UI) for websites.

In this article we'll go over the possibilities to test React based websites, using the React Testing Library and [Selenium](https://testingbot.com/support/web-automate/selenium).

## Table of Contents

- [What is React Testing Library?](https://testingbot.com#react)
- [How can I write a React test?](https://testingbot.com#how)
- [How can I use Selenium to test React websites?](https://testingbot.com#selenium)
- [How TestingBot tests your React websites.](https://testingbot.com#testingbot)

## What is React Testing Library?

React Testing Library was built specifically to test React components. It builds on top of the DOM Testing Library and adds APIs to test any React component. It is a light-weight solution to create tests, with an emphasis on creating maintainable tests. It is mostly run using Jest, but can be used with other test libraries, provided you install `jsdom` and `global-jsdom`.

Several functions are added on top of `react-dom` and `react-dom/test-utils`, encouraging best testing practices.

The library, which is a replacement for Enzyme, adds methods to locate elements in the DOM by using a `data-testid` attribute.

To install React Testing Library, simply execute the following command:

```bash
npm install --save-dev @testing-library/react
```

## How can I write a React test?

Once you've installed React Testing Library, you can quickly add your very first test, either in Javascript or Typescript. See the example below, where we'll render a React component, perform various actions and finally verify the outcome.

```javascript
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import '@testing-library/jest-dom'
import Fetch from './fetch'

test('displays pricing', async () => {
  // ARRANGE
  render()

  // ACT
  await userEvent.click(screen.getByText('Purchase'))
  await screen.findByRole('heading')

  // ASSERT
  expect(screen.getByRole('heading')).toHaveTextContent('thank you')
  expect(screen.getByRole('button')).toBeDisabled()
})
```

In the example above, we'll open the Pricing page, click on Purchase and verify if there was a thank you message.

## How can I use Selenium to test React websites?

Selenium is an open-source testing framework, capable of running browser tests against any website. For Selenium to run tests on your websites, it does not matter whether it is created with PHP, Ruby on Rails, NextJS or React.

Below is an example on how to run a Selenium test against a website built with React.

```javascript
const webdriver = require('selenium-webdriver');
const capabilities = {
 'platform' : 'WIN10',
 'browserName' : 'chrome',
 'version' : 'latest',
 'name': 'NodeJS Sample Test'
}
async function runTest () {
  let driver = new webdriver.Builder()
    .usingServer('https://hub.testingbot.com/wd/hub')
    .withCapabilities(capabilities)
    .build();
  await driver.get("https://react.dev/");
  try {
    await driver.wait(webdriver.until.titleMatches(/React/i), 5000);
  } catch (e) {
    console.error(e)
  }
  await driver.quit();
}
runTest();
```

The code example above will start a Chrome browser session on Windows 10, navigate to the React documentation website and verify if the title of the page is correct.

## How TestingBot tests your React websites.

TestingBot provides a grid of highly optimised virtual machines and physical devices, capable of testing your React based website.

The advantage of using TestingBot is that you can connect your Selenium, Puppeteer, [Playwright](https://testingbot.com/support/web-automate/playwright) or other web automation test with an online grid of browsers, capable of running tests in parallel.

If you want to run multiple React tests simultaneously, you can use TestingBot to speed up the process.

Every test session comes with a video recording of the test session and generated logs.

Topics [Selenium](https://testingbot.com/resources/articles/topic/selenium) 

## Sidebar

### TestingBot Cloud Testing

Run automated, manual and visual tests on remote browsers and devices. Sign up for a free trial.

[Free Trial](https://testingbot.com/users/sign_up)

### Latest articles

[![Selenium Python Tutorial](https://testingbot.com/assets/resources/articles/51-39337d128e18d16ddec5fe39124c2302f334e0f21e06f361cfd19e0b719e8861.webp)](https://testingbot.com/resources/articles/python-selenium-web-automation-test)

#### [Selenium Python Tutorial](https://testingbot.com/resources/articles/python-selenium-web-automation-test)

Getting started with Selenium WebDriver in Python: a firs...

[Read article →](https://testingbot.com/resources/articles/python-selenium-web-automation-test)

[![Handling Exceptions with Selenium Webdriver](https://testingbot.com/assets/resources/articles/43-044fb4e2070e941fec050b38f1c4ed34a06e7c8b63c67a6b8758805869eb75be.webp)](https://testingbot.com/resources/articles/exception-handling-with-selenium)

#### [Handling Exceptions with Selenium Webdriver](https://testingbot.com/resources/articles/exception-handling-with-selenium)

The Selenium WebDriver exceptions you will actually hit, ...

[Read article →](https://testingbot.com/resources/articles/exception-handling-with-selenium)

[![ElementClickInterceptedException in Selenium](https://testingbot.com/assets/resources/articles/33-47ac7bd953d8c5e5d1274bfe324e755e37c21003cf9224b826e4833a9f1e9001.webp)](https://testingbot.com/resources/articles/selenium-elementclickinterceptedexception)

#### [ElementClickInterceptedException in Selenium](https://testingbot.com/resources/articles/selenium-elementclickinterceptedexception)

What causes an ElementClickInterceptedException in Seleni...

[Read article →](https://testingbot.com/resources/articles/selenium-elementclickinterceptedexception)

## Other Articles

[![Selenium and Generative AI](https://testingbot.com/assets/resources/articles/28-af707bf052844eb00f861bb6ebba57e6be4479dde1c78a5df4e70d2f597a8b18.webp)](https://testingbot.com/resources/articles/generative-ai-selenium "Selenium and Generative AI")

### [Selenium and Generative AI](https://testingbot.com/resources/articles/generative-ai-selenium)

How to use generative AI to produce realistic test data for Selenium runs, and why varied data uncovers bugs that fixed fixtures never will.

[Read article →](https://testingbot.com/resources/articles/generative-ai-selenium)

[![Getting Started with IntelliJ and Selenium WebDriver](https://testingbot.com/assets/resources/articles/16-511fdda6b13b4e7660736fb97eb23be9b62874f39294870fb66212303d530cca.webp)](https://testingbot.com/resources/articles/getting-started-with-webdriver-in-java-using-intellij "Getting Started with IntelliJ and Selenium WebDriver")

### [Getting Started with IntelliJ and Selenium WebDriver](https://testingbot.com/resources/articles/getting-started-with-webdriver-in-java-using-intellij)

How to set up IntelliJ IDEA for Selenium WebDriver: the project, browser drivers, JUnit, and running the resulting tests in the cloud.

[Read article →](https://testingbot.com/resources/articles/getting-started-with-webdriver-in-java-using-intellij)

[![How to Handle Cookies in Selenium WebDriver](https://testingbot.com/assets/resources/articles/9-5a522a91a2140dbb74c2c0b484c669aed90159647c66f1ab98cb1b11579fea6e.webp)](https://testingbot.com/resources/articles/handling-cookies-with-selenium "How to Handle Cookies in Selenium WebDriver")

### [How to Handle Cookies in Selenium WebDriver](https://testingbot.com/resources/articles/handling-cookies-with-selenium)

Handling cookies with Selenium WebDriver is a common task, since most websites use cookies. In this guide, we'll show you how to do this with Selenium.

[Read article →](https://testingbot.com/resources/articles/handling-cookies-with-selenium)

[![How to use the Actions Class In Selenium](https://testingbot.com/assets/resources/articles/8-f84768dacc47dbc268338db641c2c210f5da0b9d258f4ea8592d298b015473bf.webp)](https://testingbot.com/resources/articles/what-are-selenium-actions "How to use the Actions Class In Selenium")

### [How to use the Actions Class In Selenium](https://testingbot.com/resources/articles/what-are-selenium-actions)

Selenium WebDriver comes with an Action Class, which allows you to simulate user input events, such as mouse and keyboard actions.

[Read article →](https://testingbot.com/resources/articles/what-are-selenium-actions)

## Ready to start testing?
[Start a free trial](https://testingbot.com/users/sign_up)
