cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JavaScript Click Event in Synthetic Monitoring

vuthayak
Visitor

Hi all, currently running into issues with a click event on a synthetic monitor, so I am attempting using a JavaScript event to simulate it. The element has all the necessary event listeners, and when the code is tested in the console under developer tools, it functions. However, when I place the same code under my JavaScript event I run into an issue. Does anyone have a solution to this?

vuthayak_0-1731952218022.png

vuthayak_1-1731952251031.png

 

4 REPLIES 4

the question is `why you're going to use javascript? if you have a condition please mention it to get the complete context to be able to help you in the proper way, because the btn element may be absence, accordingly you wouldn't get any response.

however, try the following one, is checking 

let btn = document.querySelectorAll('#leftFooterBtn:first-child');
if(btn.length == 1){
   btn[0].click();
}else{
   var message = 'left footer button element is not exists!';
   api.fail(message)
}

 

BR,
Mostafa Hussein.

Certified Dynatrace Professional | Certified Dynatrace Services - Observability | Dynatrace Partner yourcompass.ca

Hi Mostafa, I am using javascript since my normal clickpath event is unable to detect the button element with the locators I provide it. For example, if I add a click event with the locator "#leftFooterBtn", it fails to interact with the button.

 

Also, the code solution you provided does not seem to be working, although the button element is present.

vuthayak_0-1732025732793.png

 

is this button requires any type of authentication or specific user permission to be visible ?

Certified Dynatrace Professional | Certified Dynatrace Services - Observability | Dynatrace Partner yourcompass.ca

It does not, however I found out the reason it is not working. Dynatrace Javascript code executes in the topmost level of the HTML DOM on the webpage. My code is in an iframe, which couldn't directly interact with the topmost level. Here is my solution:

iframe = document.getElementById("iframe-element");
btn = iframe.contentDocument.getElementById("leftFooterBtn");
btn.click();

 

Featured Posts