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.
Hello !
I'm testing how to get the contents of a label. Running this command on the google chrome console did work, but I tried to put in the component did not work. What am I doing wrong?
procedure TMiniBrowserFrm.Button4Click(Sender: TObject);
var
X: String;
begin
X:=chromium1.browser.MainFrame.ExecuteJavaScript('document.getElementsByName("label")[3].innerHTML;','about:blank',0);
end;
It's not possible to get the JavaScript results in that way. You need to register a JavaScript extension and send the results back to the main browser process.
The JSExtension demo has all the code you need. Run it, right-click on the web page and select "Visit DOM in JavaScript".