Page 1 of 1

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

Posted: Sun Jul 23, 2017 1:57 pm
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.

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

Posted: Mon Jul 24, 2017 9:05 pm
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.

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

Posted: Sun Mar 29, 2020 6:46 am
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).

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

Posted: Mon May 18, 2020 3:40 pm
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.

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

Posted: Tue May 19, 2020 10:42 am
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.

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

Posted: Tue May 19, 2020 11:51 am
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 :)

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

Posted: Tue May 19, 2020 12:20 pm
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.

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

Posted: Sun Jan 17, 2021 10:11 pm
by programci81
hi voltov
can you send me the source code