<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article How to add conditional JavaScript code to close the intermittent pop-up on  a Browser clickpath monitor. in Troubleshooting</title>
    <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-add-conditional-JavaScript-code-to-close-the-intermittent/ta-p/209319</link>
    <description>&lt;H2&gt;Summary&lt;/H2&gt;
&lt;P&gt;Some websites have intermittent pop-ups. To avoid failed executions in browser clickpath monitors caused by these inconsistent load events, you can add &lt;STRONG&gt;conditional JavaScript&lt;/STRONG&gt; to detect whether a specific element exists, and then programmatically close the step.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="paragraph-in-scc-markdown-text ___1ngh792 ftgm304 f1iaxwol"&gt;This guide shows how to implement a simple, reliable JavaScript check inside a Dynatrace browser monitor.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2 id="toc-hId--705370114"&gt;Problem&lt;/H2&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Conditional JavaScript allows you to control the logic and move on when the expected element appears or change the path when it does not.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H2&gt;Resolution&lt;/H2&gt;
&lt;H3&gt;Conditional JavaScript to Detect an Element and Close the Pop-up&lt;/H3&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Go to the relevant page in a Chrome browser.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right-click on the element that you want to interact with on the pop-up page, then select &lt;STRONG&gt;Inspect. &lt;/STRONG&gt;This&amp;nbsp;will open the element in developer tools.&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image1.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11008i6D9DD1F9C58A1C90/image-size/large?v=v2&amp;amp;px=999" role="button" title="image1.png" alt="image1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image2.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11009iA639DEA8160F0049/image-size/large?v=v2&amp;amp;px=999" role="button" title="image2.png" alt="image2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Check the element tag and its attributes, then write some JavaScript code. Either:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Check the length of the element. If its greater than 0, then perform the click&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if(document.querySelectorAll('button[class="btn cancel"]').length&amp;gt;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();
}&lt;/LI-CODE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;Check if the element exists, and if it does, click on the pop-up.&amp;nbsp;&lt;BR /&gt;&lt;LI-CODE lang="markup"&gt;var el = document.querySelector("#okButtonText_1");
if (el) {
    el.click();
}​&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Add this JavaScript code to a new JavaScript Event in your browser clickpath monitor&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image3.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11010iB05DAC2859591964/image-size/large?v=v2&amp;amp;px=999" role="button" title="image3.png" alt="image3.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;What's Next&lt;/H2&gt;
&lt;P&gt;If this doesn't work, it may be that you need to try a different locator or to fire some events, see&amp;nbsp;&lt;A id="link_7" class="page-link lia-link-navigation lia-custom-event" href="https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-click-event-with-help-of-Javascript-on-browser/ta-p/244503" target="_blank" rel="noopener"&gt;How to perform click event with help of Javascript on browser click path synthetic monitor incase of recorded click event not working.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;Related Reading&lt;/H3&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp; &lt;A href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/browser-clickpath-events#javascript-event-api" target="_self"&gt;Browser monitor JavaScript events&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp; &lt;A href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors" target="_self"&gt;Configure browser monitors&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2026 16:40:02 GMT</pubDate>
    <dc:creator>Mareeswaran</dc:creator>
    <dc:date>2026-03-10T16:40:02Z</dc:date>
    <item>
      <title>How to add conditional JavaScript code to close the intermittent pop-up on  a Browser clickpath monitor.</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-add-conditional-JavaScript-code-to-close-the-intermittent/ta-p/209319</link>
      <description>&lt;H2&gt;Summary&lt;/H2&gt;
&lt;P&gt;Some websites have intermittent pop-ups. To avoid failed executions in browser clickpath monitors caused by these inconsistent load events, you can add &lt;STRONG&gt;conditional JavaScript&lt;/STRONG&gt; to detect whether a specific element exists, and then programmatically close the step.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="paragraph-in-scc-markdown-text ___1ngh792 ftgm304 f1iaxwol"&gt;This guide shows how to implement a simple, reliable JavaScript check inside a Dynatrace browser monitor.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2 id="toc-hId--705370114"&gt;Problem&lt;/H2&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Conditional JavaScript allows you to control the logic and move on when the expected element appears or change the path when it does not.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H2&gt;Resolution&lt;/H2&gt;
&lt;H3&gt;Conditional JavaScript to Detect an Element and Close the Pop-up&lt;/H3&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Go to the relevant page in a Chrome browser.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Right-click on the element that you want to interact with on the pop-up page, then select &lt;STRONG&gt;Inspect. &lt;/STRONG&gt;This&amp;nbsp;will open the element in developer tools.&lt;/P&gt;
&lt;DIV id="tinyMceEditorMareeswaran_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image1.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11008i6D9DD1F9C58A1C90/image-size/large?v=v2&amp;amp;px=999" role="button" title="image1.png" alt="image1.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image2.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11009iA639DEA8160F0049/image-size/large?v=v2&amp;amp;px=999" role="button" title="image2.png" alt="image2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Check the element tag and its attributes, then write some JavaScript code. Either:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Check the length of the element. If its greater than 0, then perform the click&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if(document.querySelectorAll('button[class="btn cancel"]').length&amp;gt;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();
}&lt;/LI-CODE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;Check if the element exists, and if it does, click on the pop-up.&amp;nbsp;&lt;BR /&gt;&lt;LI-CODE lang="markup"&gt;var el = document.querySelector("#okButtonText_1");
if (el) {
    el.click();
}​&lt;/LI-CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Add this JavaScript code to a new JavaScript Event in your browser clickpath monitor&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image3.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/11010iB05DAC2859591964/image-size/large?v=v2&amp;amp;px=999" role="button" title="image3.png" alt="image3.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;What's Next&lt;/H2&gt;
&lt;P&gt;If this doesn't work, it may be that you need to try a different locator or to fire some events, see&amp;nbsp;&lt;A id="link_7" class="page-link lia-link-navigation lia-custom-event" href="https://community.dynatrace.com/t5/Troubleshooting/How-to-perform-click-event-with-help-of-Javascript-on-browser/ta-p/244503" target="_blank" rel="noopener"&gt;How to perform click event with help of Javascript on browser click path synthetic monitor incase of recorded click event not working.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;Related Reading&lt;/H3&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" href="https://community.dynatrace.com/t5/Troubleshooting/Synthetic-Troubleshooting-Map/ta-p/250426" target="_blank" rel="noopener"&gt;Synthetic Troubleshooting Map&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp; &lt;A href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/browser-clickpath-events#javascript-event-api" target="_self"&gt;Browser monitor JavaScript events&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":open_book:"&gt;📖&lt;/span&gt;&amp;nbsp; &lt;A href="https://docs.dynatrace.com/docs/observe/digital-experience/synthetic-monitoring/browser-monitors/configure-browser-monitors" target="_self"&gt;Configure browser monitors&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2026 16:40:02 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/How-to-add-conditional-JavaScript-code-to-close-the-intermittent/ta-p/209319</guid>
      <dc:creator>Mareeswaran</dc:creator>
      <dc:date>2026-03-10T16:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to add conditional JavaScript code to close the intermittent popup on Browser click path monitor.</title>
      <link>https://community.dynatrace.com/t5/Troubleshooting/How-to-add-conditional-JavaScript-code-to-close-the-intermittent/tac-p/212135#M220</link>
      <description>&lt;P&gt;great write up thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 19:32:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Troubleshooting/How-to-add-conditional-JavaScript-code-to-close-the-intermittent/tac-p/212135#M220</guid>
      <dc:creator>ChadTurner</dc:creator>
      <dc:date>2023-05-12T19:32:38Z</dc:date>
    </item>
  </channel>
</rss>

