Page 1 of 1

Click doesn't work in JS

Posted: Mon May 12, 2025 9:52 am
by Sinisterius
Can you tell me why the button click doesn't work in executeScript?
Here is an example

//****************************
func :=
function ckickElem() {
let sub = document.querySelectorAll(''[data-testid="trap-drawer"]'');
if(sub[0] != undefined) {
console.log(sub[0].childNodes[1]);
sub[0].childNodes[1].click();
}
}
ckickElem();
wbBrowser.ExecuteScript(func);
//************************

sub[0].childNodes[1] - exists

This is one example.

Everything is working fine through the developer's console

Re: Click doesn't work in JS

Posted: Mon May 12, 2025 4:36 pm
by salvadordf
Hi,

I just checked this issue in the MiniBrowser demo.

I loaded this forum and I selected the menu option "Execute JavaScript..." with the following code :

Code: Select all

document.getElementsByName('autologin')[0].click();
The "Remember me" checkbox at the bottom has an id value of "autologin" and it was checked after executing that code.

Perhaps your web page detects if an event was initiated by the user :
https://stackoverflow.com/questions/29798010/detect-whether-an-event-is-triggered-by-user-and-not-programmatically

Re: Click doesn't work in JS

Posted: Tue May 13, 2025 8:44 am
by Sinisterius
The script is triggered via the developer's console, so I believe that the page does not take into account who is performing the click.