2

How can I send a mouse onclick message to TWebBrowser in Delphi? The OnClick message must be sent to specific control appears in website.

for Example i have a radio button appears in the website named XXXRB and I want send the message to that Radio button (which is named XXXRB) to select it.

How can I do it?

Regards.

user1512094
  • 611
  • 2
  • 10
  • 23

2 Answers2

3

can you call JS from Delphi ?

http://www.delphidabbler.com/articles?article=21

http://jansfreeware.com/articles/delphi-ie-javascript.html

http://www.programmersheaven.com/article/12946-How+to+call+JavaScript+functions+in+a+TWebBrowser+from+Delphi/info.aspx


probably there should be way

http://www.roseindia.net/javascript/javascript-click-method.shtml


To locate the control DOM Object you may try collections such as GetXXXByName or libraries like jQuery or custom JS code.

however that is the question on Internet Epxlorer + JavaScript, not on Delphi.

Arioch 'The
  • 15,799
  • 35
  • 62
  • Then you should use only pure Delphi. The only pure Delphi HTML renderer i know is http://code.google.com/p/thtmlviewer/ Dunno if it will suite you. If you chosen to render HTML pages inside Microsoft Internet Explorer - then better play by its rules. Same if you'd like to switch from MSIE to Chrome Embedded lib – Arioch 'The Aug 20 '12 at 11:11
  • This is not an internet explorer + Java Script quesion...you can see the tags of the question...Delphi, OnClick and TWebBrowser... – user1512094 Aug 20 '12 at 11:13
  • 1
    TWebBrowser IS Internet Explorer ActiveX interface. – Arioch 'The Aug 20 '12 at 11:15
  • TWebBrowser is a VCL Component in Delphi and the tag describes it as a VCL component not as an ActiveX Interface. – user1512094 Aug 20 '12 at 11:21
  • You may also try googling for using TWebBrowser for HTML parser. They say IHTMLDocument2 ActiveX interface can be got from it. Maybe that can be used to get DOM tree, and after you would scan that tree maybe JS methods would be exposed and .check() method can be called directly, who knows. But internal JS search by ByTag or ByName collections are probably faster than total enumeration of the whole DOM tree via IUknown wrappers over each node. – Arioch 'The Aug 20 '12 at 11:22
  • Look at the right column - for example u can see http://stackoverflow.com/questions/7448817 what does it described ? MSIE errors happening inside TWB. How can it be ? It is a well known fact what is TWebBrowser. http://docwiki.embarcadero.com/Libraries/en/SHDocVw.TWebBrowser what does it say the ancestor is ? TOLEControl. What OLE is ? read wikipedia. Like it or hate it, that's how it always were. – Arioch 'The Aug 20 '12 at 11:26
  • I don't care about the wikipedia...you've got to read the tag description which is the only text appears when you choose the tag in the question... http://stackoverflow.com/tags/twebbrowser/info – user1512094 Aug 20 '12 at 11:28
  • Open the sources and compare c:\RAD Studio\9.0\source\internet\SHDocVw.pas vs c:\RAD Studio\9.0\OCX\Servers\ExcelXP.pas If you want to believe there is much difference - you would only fool yourself. TWebBrowser is MSIE and always were. – Arioch 'The Aug 20 '12 at 11:29
  • The Delphi manual, i gave link above, directly states 'This DLL ships with Internet Explorer 4 and later.' No need to link SO wiki then. SHDocVw.TWebBrowser is IWebBrowser2 interface. TWebBrowser.Document is probably giving you IHTMLDocument2 interface. That is told to give you filtered collection of elements. http://www.progtown.com/topic96805-ihtmlbrowser2.html http://msdn.microsoft.com/en-us/library/aa752582.aspx Those nodes would probably expose some properties and JS methods to be invoked by Dephi. But you already have a few readymade articles how to call JS command from Delphi. up 2 u. – Arioch 'The Aug 20 '12 at 11:38
  • 1
    "TWebBrowser is a VCL control". Oh that's made my day!! – David Heffernan Aug 20 '12 at 12:25
  • 1
    well, technically all wrappers are VCL components - that is exactly what wrappers are needed for :-) 'Using very broad meaning of " VCL component" term :-) ' – Arioch 'The Aug 20 '12 at 13:46
2

No need for javascript as Arioch implies. You can have access to the complete DOM via TWebBrowser.Document. There are many resources on the net on this subject, this is the most complete one:

http://www.cryer.co.uk/brian/delphi/twebbrowser/read_write_form_elements.htm

if you look around on SO you also will find some snippets.

Community
  • 1
  • 1
whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • Nobody mentioned Java. What are you talking about? How does access to the DOM allow you to solve the problem? – David Heffernan Aug 20 '12 at 19:09
  • uch, I meant javascript offcourse. You can call Click() handler from the IE element interfaces (which you obtain via the DOM?). Or am i missing the point here? – whosrdaddy Aug 20 '12 at 20:08
  • Click() handler will be Javascript though, most likely. I don't really know this stuff though so perhaps I should shut up! – David Heffernan Aug 20 '12 at 20:46
  • @whosrdaddy, another option is to get [`more sophisticated`](http://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Sipping_Bird.jpg/501px-Sipping_Bird.jpg) hardware device and configure it (yeah, you need a complex system of capstans and it may take some time, but... :-) +1 of course! – TLama Aug 22 '12 at 13:46
  • That link wont work for me, but this one will: http://www.cryer.co.uk/brian/delphi/twebbrowser/read_write_form_elements.htm – Richard A May 12 '14 at 00:02
  • @RichardA: use this -http://www.cryer.co.uk/brian/delphi/twebbrowser/read_write_form_elements.htm – whosrdaddy May 12 '14 at 06:53