Page 1 of 1

Attempting to execute a click on an element

Posted: Tue Jan 16, 2024 9:32 pm
by miket@cbofks.com
Greetings Salvadordf,

I need to click the "#Filename" object, but the following does not work.

Code: Select all

Chromium1.browser.MainFrame.ExecuteJavaScript('document.querySelector("#Filename").click()', 'about:blank',  0);
If I go to the console, I can insert the following line and it executes correctly.

Code: Select all

document.querySelector("#Filename").click()
Am I missing something?

Something that worked before where I would simulate a mouse click on a "Choose File" button, no longer is working.

The message in the console shows: about:blank:1 File chooser dialog can only be shown with a user activation.

If executing "document.querySelector("#Filename").click()" in the console works, there must be a way to get this to work, right?

As a last resort, is there any way to stuff that command in the console window and execute it in the background?

Thanks for any ideas,
Mike

Re: Attempting to execute a click on an element

Posted: Wed Jan 17, 2024 2:32 pm
by salvadordf
Hi,

Chromium has safety measures to prevent page manipulation without user intervention.

I haven't tested this in a while but try using TChromiumCode.SendMouseClickEvent to simulate a mouse click.

If that fails then try using a browser in off-screen mode (OSR) to have full control over the mouse events.

In that mode you only need to know the screen coordinates of the button and then simulate a mouse click over it.