on
11 Apr 2023
03:50 PM
- edited on
10 Mar 2026
04:40 PM
by
HannahM
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.
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.
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:
Go to the relevant page in a Chrome browser.
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.
Check the element tag and its attributes, then write some JavaScript code. Either:
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
var el = document.querySelector("#okButtonText_1");
if (el) {
el.click();
}Add this JavaScript code to a new JavaScript Event in your browser clickpath monitor
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.
📖 Synthetic Troubleshooting Map