I got tChromium to work under Delphi 7, it should all work the same.
There are the steps I took to read elements from the DOM
First I got a wrapper from this project:
https://code.google.com/p/delphichromiumembedded/downloads/detail?name=dcef-r306.7z&can=2&q=
There is also one for XE2, would not take much to convert that to XE3, if you need help with that I will gladly help on request.
Then declare a begin and end in the tchromium
procedure TMainForm.crmLoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame); begin
if (browser <> nil) and (browser.GetWindowHandle = crm.BrowserHandle) and ((frame = nil) or (frame.IsMain)) then FLoading := True;
end;
,
procedure TMainForm.crmLoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer; out Result: Boolean);
begin
if (browser <> nil) and (browser.GetWindowHandle = crm.BrowserHandle) and ((frame = nil) or (frame.IsMain)) then begin
FLoading := False;
// see if loaded
while(httpStatusCode <> 200) do begin
Application.ProcessMessages;
Sleep(50);
end;
browser.GetMainFrame.VisitDomProc(DomProc);
end;
end;
Declare a procedure called domproc like so:
procedure DomProc(const Doc: ICefDomDocument);
var
Node: ICefDomNode;
begin
url := Doc.BaseUrl;
if(url='www.goodwebsite.com') then // check if it is the right page and not add
Node := Doc.Body.Document.GetElementById('idofwhatyouarelookingfor');
Node.SetElementAttribute('value','Hello world :D');
end;
That was the most reliable way i have found so far, you need to make sure the page is well loaded and that you are getting the dom for the right frame.
Hope it helps you, make sure to check out the example code in the download link above, that helped me out a lot.
Have fun coding, Delphi rocks!
CEF1
wrapper (since there is alsoCEF3
wrapper), then I'm afraid you've hit just this issue (the same seems tohappen in CEF3
as well). You might try some older version ofCEF1
(can't tell you which is the latest, where this worked though) and check what has changed since that version. – TLama