Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private WebView1 As WebView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
WebView1.LoadURL("https://www.b4x.com:51041/guessmynumber/index.html")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub JS(s As String)
Dim joWV As JavaObject = WebView1
joWV.RunMethodJO("getEngine"...
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private WebView1 As WebView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
WebView1.LoadURL("https://www.b4x.com:51041/guessmynumber/index.html")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub JS(s As String)
Dim joWV As JavaObject = WebView1
joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(s))
End Sub
Private Sub Button1_Click
JS($"document.getElementById("txtNumber").value="123";"$)
End Sub
Private Sub Button2_Click
JS($"document.getElementById("btnGuess").click();"$)
End Sub
yes, but this will work if you are creating your own webapp and implement a WebSocket. what i want is to go to google.com and instead of writing inside the input field of the webpage i want to do it from a b4j app.Granted that I know ZERO... I know that some Erel's examples interact with web pages, using JQueryElement.
You can learn from those examples.
[WebApp] Chatroom...
[WebApp] Web Apps Overview
You can try to inject JavaScript. I'm not sure whether it will work for all websites.
B4X:Sub Class_Globals Private Root As B4XView Private xui As XUI Private WebView1 As WebView End Sub Public Sub Initialize ' B4XPages.GetManager.LogEvents = True End Sub 'This event will be called once, before the page becomes visible. Private Sub B4XPage_Created (Root1 As B4XView) Root = Root1 Root.LoadLayout("MainPage") WebView1.LoadURL("https://www.b4x.com:51041/guessmynumber/index.html") End Sub 'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage. Private Sub JS(s As String) Dim joWV As JavaObject = WebView1 joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(s)) End Sub Private Sub Button1_Click JS($"document.getElementById("txtNumber").value="123";"$) End Sub Private Sub Button2_Click JS($"document.getElementById("btnGuess").click();"$) End Sub
thanx but none of the links are working so i cannot test it.Maybe with Selenium?
Selenium Browser Automation - Create any Robot with Browser
Selenium WebDriver - Mastering Test Automation with Selenium What is Selenium? Selenium is an open source automated testing suite for web applications across different browsers and platforms. It is quite similar to HP Quick Test Professional (QTP) only that Selenium focuses on automating...www.b4x.com
But if you know the identifiers of the elements (buttons, input boxes, ...) as you wrote, maybe that's enough (I've never fiddled with this; I was just trying to give you a hint, but they will certainly give you better ones, as has just done @roumei ).yes, but this will work if you are creating your own webapp and implement a WebSocket. what i want is to go to google.com and instead of writing inside the input field of the webpage i want to do it from a b4j app.
You can try to inject JavaScript. I'm not sure whether it will work for all websites.
B4X:Sub Class_Globals Private Root As B4XView Private xui As XUI Private WebView1 As WebView End Sub Public Sub Initialize ' B4XPages.GetManager.LogEvents = True End Sub 'This event will be called once, before the page becomes visible. Private Sub B4XPage_Created (Root1 As B4XView) Root = Root1 Root.LoadLayout("MainPage") WebView1.LoadURL("https://www.b4x.com:51041/guessmynumber/index.html") End Sub 'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage. Private Sub JS(s As String) Dim joWV As JavaObject = WebView1 joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(s)) End Sub Private Sub Button1_Click JS($"document.getElementById("txtNumber").value="123";"$) End Sub Private Sub Button2_Click JS($"document.getElementById("btnGuess").click();"$) End Sub
But if you know the identifiers of the elements (buttons, input boxes, ...) as you wrote, maybe that's enough (I've never fiddled with this; I was just trying to give you a hint, but they will certainly give you better ones, as has just done @roumei ).
Private Sub RunJavaScript (js As String) As ResumableSub
#if B4A
WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
Wait For Process_Html(html As String)
Return html
#Else If B4J
Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
#Else If B4i
Dim sf As Object = WebView1.EvaluateJavaScript(js)
Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
Return Result
#end if
End Sub
seeing can be of help
B4XWait for Javascript to complete
Dear All; if I run the script I get the last value for para3, is there a way to show each value in turn, like to wait for each script before starting the next one. Dim Javascript As String Javascript = $"B4A.CallSub('ProcessHTML', true, document.getElementById('para1').value,'para1')"$...www.b4x.com
B4X:Private Sub RunJavaScript (js As String) As ResumableSub #if B4A WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$) Wait For Process_Html(html As String) Return html #Else If B4J Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js)) #Else If B4i Dim sf As Object = WebView1.EvaluateJavaScript(js) Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String) Return Result #end if End Sub
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private WebView1 As WebView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
WebView1.LoadURL("https://www.b4x.com:51041/guessmynumber/index.html")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
RunJavaScript($"document.getElementById("txtNumber").value="123";"$)
End Sub
Private Sub Button2_Click
RunJavaScript($"document.getElementById("btnGuess").click();"$)
End Sub
Private Sub Button3_Click
Wait For (RunJavaScript($"document.getElementById("txtNumber").value;"$)) Complete(Html As String)
xui.MsgboxAsync(Html, "Get Field")
End Sub
Public Sub RunJavaScript (JS As String) As ResumableSub
#if B4A
WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
Wait For Process_Html(html As String)
Return html
#Else If B4J
Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(JS))
#Else If B4i
Dim sf As Object = WebView1.EvaluateJavaScript(js)
Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
Return Result
#end if
End Sub