Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Click doesn't work in JS

Post Reply
Sinisterius
Posts: 2
Joined: Mon May 12, 2025 9:45 am

Click doesn't work in JS

Post 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
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Click doesn't work in JS

Post 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
Sinisterius
Posts: 2
Joined: Mon May 12, 2025 9:45 am

Re: Click doesn't work in JS

Post 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.
Post Reply