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.

Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post Reply
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by salvadordf »

Hi,

If you can't use javascript I would use the new DOM visitor function found in the latest MiniBrowser demo to get the input box coordinates.

Create a new application using a TChromium in OSR mode like the SimpleOSRBrowser demo and copy the DOM visitor code from the MiniBrowser.

Then you would just have to use TChromium.SendFocusEvent, TChromium.SendMouseMoveEvent, TChromium.SendMouseClickEvent and TChromium.SendKeyEvent to simulate the mouse movement, clicks and key presses.

If you are not sure about which events should be emulated then do all the process in real life and log them using the TApplicationEvents or adding custom code to log all activities inside TChromium.SendFocusEvent, TChromium.SendMouseMoveEvent, TChromium.SendMouseClickEvent and TChromium.SendKeyEvent

Edit : I haven't checked if you can get the coordinates using the "non-javascript" DOM visitor but even if you can't, you should be able to recreate all events recorded in the real life test.
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by salvadordf »

I'm glad to hear that! :D

You're right. I should create separate demos for each functionality. The MiniBrowser has too many things in one place.
coater
Posts: 135
Joined: Sat Sep 29, 2018 1:51 pm

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by coater »

JS element operation is much easier than that by visiting dom!


can found in the visitdom demo
visit dom:

//1.set GlobalCEFApp.OnProcessMessageReceived := GlobalCEFApp_OnProcessMessageReceived;
//2. send a message from a browser to render
var
TempMsg : ICefProcessMessage;
begin
// Use the ArgumentList property if you need to pass some parameters.
TempMsg := TCefProcessMessageRef.New(RETRIEVEDOM_MSGNAME_NAME); // Same name than TCefCustomRenderProcessHandler.MessageName
abrowser.MainFrame.SendProcessMessage(PID_RENDERER, TempMsg);
end;
//3. render got the message(GlobalCEFApp_OnProcessMessageReceived), visiting dom and sending message to browser are in procedure( DOMVisitor_OnDocAvailable).
voltov
Posts: 14
Joined: Tue Jun 13, 2017 11:01 am

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by voltov »

Could you help with one thing? I can't understand how do I send some argument or information into DOMVisitor_OnDocAvailable() - I need to find coordinates of specific HTML element, but I can't send XPath of the element into method that can loop through DOM. Please help.
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by salvadordf »

Hi,

The DOMVisitor demo uses GlobalCEFApp_OnProcessMessageReceived to create a TCefFastDomVisitor2 that will execute DOMVisitor_OnDocAvailable when ICefDomVisitor.visit is triggered (see CEF4Delphi\source\uCEFDomVisitor.pas for the details).

As you can see, TCefFastDomVisitor2 has 2 extra fields (FBrowser and FFrame) that are used as parameters when DOMVisitor_OnDocAvailable is executed.

If you need more parameters in DOMVisitor_OnDocAvailable then you can send them in the process message received in GlobalCEFApp_OnProcessMessageReceived and create a custom TCefFastDomVisitor3 which will store those extra parameters.

You will need to implement a new custom TCefFastDomVisitor3 class inherited from TCefDomVisitorOwn and a new procedure type called TCefDomVisitorProc3 for example. TCefFastDomVisitor3 will store your extra parameters and a TCefDomVisitorProc3 that will be executed inside ICefDomVisitor.visit.
voltov
Posts: 14
Joined: Tue Jun 13, 2017 11:01 am

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by voltov »

Thank you for clarification, I understand now.

I used a slightly different method - inside Render process I create instance of my own class, pass all arguments into it and then I call browser.MainFrame.VisitDomProc(myClassInstance.OnDomAvailable) - passing callback from my class. Then I have all my arguments inside my class and I can loop through DOM inside my class. I managed to retrieve coordinates from Render process and to emulate click.

Thank you very very much for the CEF4Delphi framework and for support on forum!

I also have another question - is it possible to access DOM only from Render process? It would be much simpler if framework provided ability to work with DOM directly like Chromium.document.body.getFirstChild(). I know this is very complicated, but I still want to ask it it's possible, at least in theory :)
User avatar
salvadordf
Posts: 4042
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by salvadordf »

As far as I know, that's only possible if you use the "Single Process" mode which should be used for debugging purposes only.

Normally Chromium uses a different process to handle the DOM.
programci81
Posts: 1
Joined: Sun Jan 17, 2021 9:06 pm

Re: Simulate click and type (NOT using Javascript!!!) Access the DOM??

Post by programci81 »

hi voltov
can you send me the source code
Post Reply