6

How do I invoke button clicks within page content of a TWebBrowser ? I have found this code for VCL and an older version of Delphi:

WebBrowser.OleObject.Document.GetElementByID('ID HERE').Click;

I am using XE5, developing for Android and iOS so I can not use the above code. Any help or suggestions would be much appreciated. Thanks !

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
ThisGuy
  • 1,405
  • 1
  • 24
  • 51
  • Why can't you use that code? Do you not have a `TWebBrowser` control? If not, then what control do you have instead? Provide more **context** for your question. What facilities does your control offer for interacting with the page? Show some research effort of your own. – Rob Kennedy Feb 19 '14 at 01:48
  • 1
    You should do some searching on WebView which is the control that TWebBrowser wraps on Android devices. This link might have something you can use http://developer.android.com/reference/android/webkit/WebView.html - There is also a question on doing this in Javascript that may help http://stackoverflow.com/questions/16709963/programmatic-click-in-android-webview. – Graymatter Feb 19 '14 at 02:18
  • @Rob, I do have and use a TWebBrowser but my application is for FMX.. The TWebBrowser for FMX does not have a 'oleObject' subclass – ThisGuy Feb 19 '14 at 02:44
  • 4
    @RobKennedy he says "I am using XE5, developing for Android and iOS so (implies causation) I can not use the above code." so your question "why" is (a) redundant and (b) outside the scope of his question. Clearly he has researched the applicability of that code to his context and he's searching for alternatives. Had he found an alternative, he wouldn't be here asking! Perhaps once he knows how to do it, you can ask him to write a blog post or a doctoral thesis, but surely not before. – Sam Feb 19 '14 at 05:24
  • 2
    @JordanWeb No problem Jordan, but I don't think Rob fits into that stereotype either. It's just that his skill level is much higher than ours and his only fault here is trying to enforce an unreasonable standard as described in some stupid FAQ. It's that stupid FAQ's fault that some moderators come across as unnecessarily harsh when in fact they're just trying to maintain some standards. Rob wouldn't even bother with this website if he wasn't a helpful guy to begin with. So I think Rob deserves some slack just as we do with our seemingly basic questions from an expert's perspective. – Sam Feb 19 '14 at 10:07
  • I've tried to do it with js, but unfortunatelly failed (at least on Android). Can iOS implementation of `TWebBrowser` run JavaScript? – naXa stands with Ukraine Apr 11 '14 at 01:45
  • 1
    In their latest update Embarcadero has fixed hundreds of design and performance bugs for XE6. For the `TWebBrowser` component, FireMonkey now provides the `EvaluateJavaScript` method. You can use it as follows: `WebBrowser.EvaluateJavaScript('document.getElementById("BUTTON ID HERE").click();');` – naXa stands with Ukraine Apr 29 '14 at 11:37

1 Answers1

-1

For Android: It is straight forward that you may need to write a JS function in web page and than you can call the JS function using JSInterfaces.

For iOS: You may call the instance method provided in UIWebView class to call the Javascript method. For reference please see : https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006950-CH3-SW21

Usman Awan
  • 1,208
  • 2
  • 13
  • 30