# How to add conditional JavaScript code to close the intermittent pop-up on  a Browser clickpath monitor.

**URL:** <https://community.dynatrace.com/t/how-to-add-conditional-javascript-code-to-close-the-intermittent-pop-up-on-a-browser-clickpath-monitor/39202>\
**Category:** Troubleshooting\
**Tags:** browser-monitors, synthetic-monitoring\
**Created:** [April 11, 2023, 2:50pm UTC](https://community.dynatrace.com/t/how-to-add-conditional-javascript-code-to-close-the-intermittent-pop-up-on-a-browser-clickpath-monitor/39202 "2023-04-11T14:50:00Z")\
**Posts on this page:** 2\
**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:** [April 11, 2023, 2:50pm UTC](https://community.dynatrace.com/t/how-to-add-conditional-javascript-code-to-close-the-intermittent-pop-up-on-a-browser-clickpath-monitor/39202/1 "2023-04-11T14:50:00Z")

</div>

## Summary

Some websites have intermittent pop-ups. To avoid failed executions in browser clickpath monitors caused by these inconsistent load events, you can add **conditional JavaScript** to detect whether a specific element exists, and then programmatically close the step.

This guide shows how to implement a simple, reliable JavaScript check inside a Dynatrace browser monitor.

## Problem

When recording a Browser clickpath, we may record a click event to close the pop-up. However, this pop-up may appear intermittently, and so the execution will fail if the pop-up does not appear.

Conditional JavaScript allows you to control the logic and move on when the expected element appears or change the path when it does not.

## Resolution

### Conditional JavaScript to Detect an Element and Close the Pop-up

To avoid intermittent errors, we can add a JavaScript event with conditional JavaScript code to close the pop-up whenever it is seen. Follow the steps below to do this:

1. Go to the relevant page in a Chrome browser.

2. Right-click on the element that you want to interact with on the pop-up page, then select **Inspect.** This&nbsp;will open the element in developer tools.

3. Check the element tag and its attributes, then write some JavaScript code. Either:

4. Add this JavaScript code to a new JavaScript Event in your browser clickpath monitor  

## What’s Next

If this doesn’t work, it may be that you need to try a different locator or to fire some events, see&nbsp;[How to perform click event with help of Javascript on browser click path synthetic monitor incase of recorded click event not working.](https://community.dynatrace.com/topic/244503)

If you still need assistance, open a chat or support ticket and provide a link to the affected monitor and explain what your are trying to do and what you have already tried.

### Related Reading

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

📖&nbsp; [Browser monitor JavaScript events](https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/browser-clickpath-events#javascript-event-api)

📖&nbsp; [Configure browser monitors](https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors)

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [May 12, 2023, 7:32pm UTC](https://community.dynatrace.com/t/how-to-add-conditional-javascript-code-to-close-the-intermittent-pop-up-on-a-browser-clickpath-monitor/39202/2 "2023-05-12T19:32:38Z")

</div>

great write up thank you!
