# REACT data-testid target with Katalon?

**URL:** <https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337>\
**Category:** Miscellaneous\
**Created:** [September 20, 2018, 7:22pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337 "2018-09-20T19:22:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dakota](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dakota](https://forum.katalon.com/u/dakota)\
**Post date:** [September 20, 2018, 7:22pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/1 "2018-09-20T19:22:42Z")

</div>

Hello,

I’ve seen a few post on the forums detailing some methods of working with REACT applications and how to use their long string with X-Path.

Mostly this one with some great insights from Russ Thomas

> **[Testing REACT elements with Katalon Studio](https://forum.katalon.com/discussion/7513/testing-react-elements-with-katalon-studio)**
>
> Hey there! I’ve been loving Katalon, very friendly to use! My companies website has many parts built with React. Things like check-boxes, table entries, and small buttons (carots, arrows, page nums, etc) seem to NEVER work. Even by switching to...

Unfortunately, these methods have not offered much luck on our platform for automating.

My question is can we use Katalon and create either a custom keyword or variable while targeting the data-testid field for react applications.

In example with the code below, I need to target a specific button to deactivate and then reactivate a user. When using katalon spy and web recorder the system identifies “ui green tiny circular compact icon button” which wont work when running the automation due to this element representing each user on the page.

Our developers have been adding data-testid to elements for us to target but I have not found a method using Katalon. Has anyone here found a way to use this element?

I will continue to research and if I find a solution I will share on this post.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [September 20, 2018, 7:27pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/2 "2018-09-20T19:27:36Z")

</div>

Use the following CSS selector to target that example button element:

```auto
button[data-testid="group-list-card-QAST447-disable-button"]

```

In your test object, place that exact code under the CSS panel.

---

<div class="post-metadata">

**Author:** ![dakota](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dakota](https://forum.katalon.com/u/dakota)\
**Post date:** [September 20, 2018, 7:30pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/3 "2018-09-20T19:30:13Z")

</div>

That was quick Russ, thank you! I will implement and reply with results.

---

<div class="post-metadata">

**Author:** ![dakota](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dakota](https://forum.katalon.com/u/dakota)\
**Post date:** [September 21, 2018, 8:49pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/4 "2018-09-21T20:49:14Z")

</div>

Unfortunately, Russ’s suggestion did not work on my solution. When running the log, it displays the system cannot click on the object I created. Not sure if I created this object wrong but below is a screenshot of my configuration.

StepFailedException: Unable to click on object ‘Object Repository/Deactivate Button’ (Root cause: org.openqa.selenium.NoSuchWindowException: Browsing context has been discarded

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [September 22, 2018, 2:17am UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/5 "2018-09-22T02:17:28Z")

</div>

I need a bit more (perhaps a lot more) context than you provided here. (The CSS looks fine, btw.)

That error “Browsing context has been discarded” is associated with things like:

- A closed window

- A closed browser tab (window)

- Unloaded or partially unloaded document

- Discarded frame/iframe elements

- Detached document fragments (maybe?)

- etc

The question we’re left with is: what happened prior to this error being issued?

Change the log viewer to flat output and paste the stuff that came before (dozen or so lines should be enough). Also, post the relevant test code.

---

<div class="post-metadata">

**Author:** ![dakota](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dakota](https://forum.katalon.com/u/dakota)\
**Post date:** [September 27, 2018, 6:26pm UTC](https://forum.katalon.com/t/react-data-testid-target-with-katalon/13337/6 "2018-09-27T18:26:17Z")

</div>

Hello again,

I used another method to fix this issue, due to the nature of how we build our solution there were neighboring elements attached in the xpath of the object which was causing the automation to be confused.

For anyone having a similar issue with react or another structure check your objects and ensure there are not neighboring elements on the page that mau confuse your automation by having multiple selections.

Thanks again for your help Russ.
