---
title: "Discussion on \"Testing library (React): Selecting text in multiple HTML elements\" | Hashnode"
description: "Discussion on \"Testing library (React): Selecting text in multiple HTML elements\". <h3 data-testid=\"hello-header\">Hello <strong>World</strong></h3>\n\n*ByRole\nscreen.getByRole('heading', { name: 'Hello World' });\n\nor.toHaveTextContent\nexpect(screen.getByTestId('hello-header')).toHaveTextContent('Hello World');"
url: "https://hashnode.com/posts/testing-library-react-selecting-text-in-multiple-html-elements/670fcac3b96e3cf3b62b8a52"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Testing library (React): Selecting text in multiple HTML elements](https://fullchee.hashnode.dev/testing-library-react-selecting-text-in-multiple-html-elements?utm_source=hashnode&utm_medium=feed)

<h3 data-testid="hello-header">Hello <strong>World</strong></h3> \*ByRole screen.getByRole('heading', { name: 'Hello World' }); or.toHaveTextContent expect(screen.getByTestId('hello-header')).toHaveTextContent('Hello World');

Oct 16, 2024 · 1 min read · fullchee.hashnode.dev  
Updated Aug 20, 2025  
Read the article

-   [#testing-library](https://hashnode.com/tag/testing-library)

## Written by

[Fullchee Zhang](https://hashnode.com/@Fullchee)

@Fullchee · Toronto, Canada

  
[View profile](https://hashnode.com/@Fullchee)

Full Stack Dev at Forma AI

React, Django and SQL developer at Forma.ai

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
