18 Nov 2024 05:51 PM - last edited on 19 Nov 2024 07:36 AM by MaciejNeumann
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?
18 Nov 2024 10:36 PM
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.
19 Nov 2024 02:15 PM
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.
19 Nov 2024 11:12 PM - edited 19 Nov 2024 11:13 PM
is this button requires any type of authentication or specific user permission to be visible ?
20 Nov 2024 02:28 PM
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();