Troubleshooting
Articles about how to solve the most common problems
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Mareeswaran
Dynatrace Advisor
Dynatrace Advisor

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 will open the element in developer tools.

     

    image1.pngimage2.png

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

    1. Check the length of the element. If its greater than 0, then perform the click

      if(document.querySelectorAll('button[class="btn cancel"]').length>0) // For example on this page, element tag is button and attribute is class="btn cancel" . You can modify this based on your application page.
      {
       document.querySelector('button[class="btn cancel"]').click();
      }

      or

    2. Check if the element exists, and if it does, click on the pop-up. 
      var el = document.querySelector("#okButtonText_1");
      if (el) {
          el.click();
      }​
  4. Add this JavaScript code to a new JavaScript Event in your browser clickpath monitorimage3.png

 

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 How to perform click event with help of Javascript on browser click path synthetic monitor incase of...

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

📖  Synthetic Troubleshooting Map

📖  Browser monitor JavaScript events

📖  Configure browser monitors

Version history
Last update:
‎10 Mar 2026 04:40 PM
Updated by:
Comments
ChadTurner
DynaMight Legend
DynaMight Legend

great write up thank you!