Android Question How To Programmatically Click a Web Button??

air cover

Member
Licensed User
Longtime User
How To Programmatically Click a Web Button created by HTML that is being displayed in a WebView object by my app?

I have a simple app that browses web pages. They are displayed in WebView1. One of the html web pages displays a clickable button. It's part of the web page, not part of my app, but of course it shows up in my app because my app is displaying that web page.


A user could currently click this button by pressing it manually. Once clicked, my WebView1 window displays an updated html page.

However, what I'd LOVE to be able to do is to click that one button programmatically so that my users don't have to bother pressing that button.

Possible? Easy? Already done and my search just didn't find it?

Any help would be appreciated. Thanks!
 
using

Code:
wve.executeJavascript(wv,"document.getElementById('lst-ib').value='test';document.forms(0).submit()")

it opens google, types "test" in the search and do the actual search for you.
 
Upvote 0
but as I said before you could bypass the first step in 99% of the cases that you don't need all this hassle.
 
Upvote 0
can you share the link or send it by private message?

then I'll see if some trickery can be used to do it the easy way.
 
Upvote 0
if the button has an id you could use it with this

Code:
Sub Globals
Dim wv As WebView
Dim wve As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
wv.Initialize("wv")
wv.JavaScriptEnabled=True

Activity.AddView(wv,0,0,100%x,100%y)
wv.LoadUrl("http://www.google.com")
End Sub

Sub wv_PageFinished (Url As String)
wve.addWebChromeClient(wv,"")
wve.executeJavascript(wv,"alert('yo')")
End Sub

That's nice, clean code, thanks. It does display your google.com page and then say "yo" (then crashes).

Replacing the "yo" javascript with
Code:
wve.executeJavascript(wv,"document.getElementById('lst-ib').value='B4A';document.forms(0).submit()")
displays "B4A" in the google text input box, but doesn't search (possibly suggesting that the search button wasn't programmatically clicked).
 
Upvote 0
indeed, the app closes here aswell but it doesn't give an error in the logs.
 
Upvote 0
OK, this is cool. B4A has an asynch subroutine that lets you code after your web page loads into the webview tool! Well done, guys!

Code:
 Sub WebView1_PageFinished (Url As String)
    MyWebViewExtras.executeJavascript(WebView1,"alert('yo')")
End Sub
 
Upvote 0
Thanks...but weirdly enough, in Release mode the web page is loading, but the "B4A" text isn't even being entered into the input box...whereas in debug mode it does get entered, just not searched.
 
Upvote 0
well, I said it before. you can bypass that misery if you know how to transmit the data without the use of the webview.
 
Upvote 0
Back
Top