I'm use WebViewExtras lib, there is two webpage, the original page is online website, I download a piece of source as local page for debug.
Just like attachment picture, after click next on the webpage1, I want auto insert edittext content when button is clicked on the webpage2, and copy the string from the webpage2.
I don't know how to catch this html element:
Just like attachment picture, after click next on the webpage1, I want auto insert edittext content when button is clicked on the webpage2, and copy the string from the webpage2.
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim WebViewExtras1 As WebViewExtras
Dim WebView1 As WebView
Private Button1 As Button
Private Button2 As Button
Private EditText1 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main.bal")
'WebView1.SetLayout(0,0,100%x,80%y)
' add the JavascriptInterface to WebView1
WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
WebViewExtras1.addWebChromeClient(WebView1,"Chrome")
EditText1.text="1111111 2222222 3333333"
WebView1.LoadUrl("file:///android_asset/test2.html")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
........
End Sub
Sub Button2_Click
..........
End Sub
Sub WebView1_PageFinished (Url As String)
Dim Javascript As String
Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
Log("PageFinished: "&Javascript)
'If Url="url_of_the_login_page" Then
Dim Javascript As String
Dim MyWebViewExtras As WebViewExtras ' you could make this a global variable if you use it elsewhere in your code
Javascript ="B4A.CallSub('ProcessHTML', true, document.getElementById('field1').getAttribute('value'))"
MyWebViewExtras.executeJavascript(WebView1, Javascript)
Log("Javascript")
' alternatively you could execute the javascript without requiring WebViewExtras by using the javascript protocol:
' WebView1.LoadUrl("javascript:"&Javascript.ToString)
Log("PageFinished: "&Javascript)
End Sub
Sub ProcessHTML(Html As String)
' This is the Sub that we'll get the web page to send it's HTML content to
' Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
Log("ProcessHTML: "&Html)
End Sub
I don't know how to catch this html element:
B4X:
<div class="align-center input">
<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
<input onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="field1" type="tel" value="" pattern="[0-9]*">
</div>
</div>
Last edited: