# How to perform a click event using Javascript on browser clickpath synthetic monitors

**URL:** <https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384>\
**Category:** Troubleshooting\
**Tags:** browser-monitors, synthetic-monitoring\
**Created:** [May 1, 2024, 11:00am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384 "2024-05-01T11:00:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [May 1, 2024, 11:00am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/1 "2024-05-01T11:00:25Z")

</div>

## Summary

When a recorded click fails in a Dynatrace Synthetic Browser Monitor, you can use a **JavaScript event** to manually dispatch the required pointer and mouse events (`pointerdown`, `pointerup`, `mouseup`, `click`) so the application processes the interaction correctly.&nbsp;This approach is commonly required for modern web applications that rely on multiple event listeners or advanced front‑end frameworks.

## Problem

In some scenarios, a **recorded click event** in a Browser Clickpath Synthetic Monitor **does not work during execution or playback**.This usually happens because the target application **doesn’t respond to a simple `.click()` action**, but instead expects a **combination of pointer and mouse events** to be fired in a specific order.

## When JavaScript Click Events Are Required

You typically need a JavaScript click event when:

- The recorded click works during recording but **fails during monitor execution**
- The application relies on **custom JavaScript event listeners**
- The element reacts to **pointer events** , not just click events
- The application uses **modern UI frameworks** or **Shadow DOM**

In these cases, dispatching the required events manually ensures the application behaves as if a real user performed the action.

## How to Identify Required Events (Chrome DevTools)

Before writing any JavaScript, verify which events the application expects.

### Step 1 – Inspect the element

1. Open the application in **Google Chrome**
2. Right‑click the element you want to interact with
3. Select **Inspect** to open Chrome DevTools, which will open the developer tools  
 ![Inspect.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/3/36ab48764fe63f15d6c6d26b14ed0f6664e85e51.jpeg)

### Step 2 – Check event listeners

1. In DevTools, select the element

2. Open the **Event Listeners** tab

3. Identify which events are registered (for example: `click`, `pointerdown`, `pointerup`, `mouseover`)  
These are the events you’ll need to dispatch manually.

4. 

## JavaScript Example: Triggering Pointer and Mouse Events

The following example demonstrates how to dispatch multiple events to reliably simulate a real user click.

### Step 3 – Copy the JavaScript selector

In Chrome DevTools:

- Right‑click the element in the DOM tree
- Select **Copy → Copy JS path**

 ![Copy JS Path.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/b/f/bf0ece34586eeb0b46f952695b8540c6769a1e59.jpeg)

### Step 4 – Add a JavaScript Event to the Browser Clickpath

Paste the following code into a **JavaScript event** in your Browser Clickpath Synthetic Monitor, and replace the selector with your own.

 ![Add JS event.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/6/4/64ec333ad15362a710cd6a5e52ad4b37b3332951.jpeg)

```markup
function triggerevent(element)
{

 var parameters1 = { isTrusted: true, pressure: 0.5, type: "pointerdown", bubbles: true, cancelable: true, cancelBubble: false };
 var parameters2 = { isTrusted: true, bubbles: true, cancelable: true, cancelBubble: false };

 var evt1 = new PointerEvent("pointerdown", parameters1);
 element.dispatchEvent(evt1);
 var evt2 = new PointerEvent("pointerup", parameters1);
 element.dispatchEvent(evt2);
 var evt3 = new MouseEvent("mouseup", parameters2);
 element.dispatchEvent(evt3);
 var evt4 = new MouseEvent("click", parameters2);
 element.dispatchEvent(evt4);

}

var element = document.querySelector("#layout-inner > dt-common-navigation").shadowRoot.querySelector("nav > nav > ul > li:nth-child(9) > a");
triggerevent(element);

```

## Example Using Shadow DOM

⚠ **Note:**  
The example above accesses the element via `shadowRoot`. This is required **only if your application uses Shadow DOM**.

- If your application **doesn’t use Shadow DOM** , remove the `.shadowRoot` portion and use a standard `querySelector()` instead.

## Common Pitfalls and Troubleshooting

If the click still does not work:

- Verify that the **correct element** is being selected
- Confirm the **required event types** in DevTools
- Ensure the element is **visible and not covered by overlays**
- Check whether the application requires **trusted events**

## When to Use Trusted Events Instead

Some applications check whether an action was triggered by a **real user** using the `isTrusted` property.In these cases, JavaScript‑dispatched events may still fail. If this happens, consider enabling **Trusted Events** in your Browser Clickpath configuration and using native click steps instead.See&nbsp;[How to interact with trusted events in a Browser Clickpath Monitor](https://community.dynatrace.com/topic/222074) for details.

## Frequently Asked Questions

**Why doesn’t `.click()` work in Synthetic Browser Monitors?**  
Some applications listen for multiple pointer or mouse events, not just a click. **When should I use JavaScript events instead of recorded clicks?**  
When recorded clicks fail during execution but work during recording. **Is this approach supported by Dynatrace?**  
Yes. Browser Clickpath Synthetic Monitors support JavaScript events for advanced interaction scenarios. **Should I always prefer Trusted Events?**  
Use Trusted Events when the application explicitly checks for real user interactions; otherwise, JavaScript events are often sufficient.

## What’s Next

If the issue persists after trying JavaScript and trusted events, open a **support chat or ticket** and provide:

- A link to the affected monitor
- The selector and JavaScript used
- A reference to this article

### **Related reading** &nbsp;

[📖&nbsp; Synthetic Troubleshooting Map](https://community.dynatrace.com/topic/250426)

📖&nbsp; [How to interact with trusted events in a Browser Clickpath Monitor](https://community.dynatrace.com/topic/222074)

📖&nbsp;&nbsp;[How to add conditional JavaScript code to close the intermittent popup on Browser click path monitor…](https://community.dynatrace.com/topic/209319)

📖&nbsp;&nbsp;[How to perform a right-click in a Browser Clickpath Synthetic Monitor](https://community.dynatrace.com/topic/233062)

📖&nbsp;&nbsp;[How to inspect and add the shadow DOM elements into synthetic script events](https://community.dynatrace.com/topic/209228)

---

<div class="post-metadata">

**Author:** ![shalnw](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@shalnw](https://community.dynatrace.com/u/shalnw)\
**Post date:** [May 3, 2024, 7:05am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/2 "2024-05-03T07:05:16Z")

</div>

Hi&nbsp;[@Mareeswaran](https://community.dynatrace.com/user/40562)&nbsp;, thank you for your suggestion. I have tried replacing all the CSS locators with DOM and it works during replay but is there anyway we could set up Dynatrace to capture the DOM locators by default (instead of CSS) while recording a flow?

---

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [May 8, 2024, 5:05am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/3 "2024-05-08T05:05:00Z")

</div>

[@shalnw](https://community.dynatrace.com/user/75349)&nbsp; Unfortunately, we don’t have way to make the synthetic recorder&nbsp;to capture the DOM locators by default and we need to inspect & add the DOM locators manually.

---

<div class="post-metadata">

**Author:** ![shalnw](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@shalnw](https://community.dynatrace.com/u/shalnw)\
**Post date:** [May 8, 2024, 5:10am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/4 "2024-05-08T05:10:51Z")

</div>

Thanks&nbsp;[@Mareeswaran](https://community.dynatrace.com/user/40562)&nbsp;, I have added the DOM locators/ events and the screenshots to my recording. The playback click path replays the expected flow and the screenshots are correct. But when I go to Analyse executions to view results, it shows just the website’s homepage. Is this inconsistency expected for Shadow DOM events?

---

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [May 8, 2024, 5:14am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/5 "2024-05-08T05:14:47Z")

</div>

[@shalnw](https://community.dynatrace.com/user/75349)&nbsp; Yes.&nbsp;If the application uses the shadowDOM elements, Dynatrace Synthetic Recorder extension not supported for recording the shadowDOM elements.&nbsp; You can refer the community article for that&nbsp;[How to inspect and add the shadow DOM elements into synthetic script events.](https://community.dynatrace.com/topic/209228)

---

<div class="post-metadata">

**Author:** ![kenyu216](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kenyu216](https://community.dynatrace.com/u/kenyu216)\
**Post date:** [November 4, 2025, 7:16pm UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/6 "2025-11-04T19:16:23Z")

</div>

Hi

I tried out this JS script method and currently encountering the error “Playback error: Exception was thrown by the JavaScript code: Cannot read properties of null (reading ‘shadowRoot’).”

 ![kenyu216_0-1762283745911.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/1170a4560c0644dfae1cf8221f313f28e9372549.png)

I’m not sure what I am missing here.

Thank you.

---

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [November 19, 2025, 8:43am UTC](https://community.dynatrace.com/t/how-to-perform-a-click-event-using-javascript-on-browser-clickpath-synthetic-monitors/45384/7 "2025-11-19T08:43:09Z")

</div>

Hi&nbsp;[@kenyu216](https://community.dynatrace.com/user/49354)

I suspect that target window may be different one and that is the reason its unable to identify the selector. You can inspect the element and check if there is any iframe are available. If so, you need to use the relevant target window like&nbsp;ruxitWin[0].frames[0]

 ![Mareeswaran_0-1763541795116.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/3/53c9b439ef8455bf7145a029b4c9ce3efe1d0327.png)
