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.

Attempting to execute a click on an element

Post Reply
miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Attempting to execute a click on an element

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Attempting to execute a click on an element

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