简体   繁体   中英

Delphi Chromium,how simulate click Button on html page

I am using TChromium component on Delphi 10. I need to transfer the text from TMemo to a textarea in html and simulate a click on button on this page.

I have been try it, but doens't work

chromium1.Browser.MainFrame.ExecuteJavaScript('document.all(id_4).value='+Memo1.text+';', '', 0);
Chromium1.Browser.MainFrame.ExecuteJavaScript('id_2.click();', '', 0);

Basically i need this code bellow but using TChromium in Delphi 10. This code bellow is on delphi7 using TWebBrownser.

WebBrowser1.OleObject.Document.all.Item('id_4', 0).value := memo1.Text;
WebBrowser1.OleObject.Document.all.Item('id_2', 0).click;

If your Memo1 contains the text:

With space in it.

...then:

document.all(id_4).value=With space in it.;

...is not valid JavaScript, because With is undefined. And the following three tokens plus the dot, too. You have to assign text to it, so in Delphi you have to use:

'document.all( id_4 ).value= "'+ Memo1.Text+ '";'

...as literal, because then it becomes valid JavaScript:

document.all( id_4 ).value= "With space in it.";

Of course: you have to take care of Memo1 's text if it contains a " itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM