B4J Question How add Value attribute to Input?

Edgardo PuntoCom

Member
Licensed User
Longtime User
Hello,

I execute the following:

B4X:
js.evalString("doc.getElementById('LoginPh').value = 'plant';")

and nothing happens, if I right click on the WebView and choose "Open Frame In New Window", then if the input is filled

What I want is to make an automatic Login

The Input is in nested frame.

My code:

B4X:
#Region  Project Attributes
    #MainFormWidth: 800
    #MainFormHeight: 650
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private we,temp As JavaObject
    Private wv1 As WebView
    Private startPage As String = "http://111.111.111.111"
    Private doc As JavaObject        ' JavaObject library
    Private js As jScriptEngine     ' jScriptengine library
   
    Dim codigo As String
    Private corr As TextField
    Private grado As TextField
    Private grado As TextField
    Private almidon As TextField
    Private conv1 As TextField
    Private cliente1 As TextField
    Private mat1 As TextField
    Private conv2 As TextField
    Private cliente2 As TextField
    Private mat2 As TextField

End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
    doc.InitializeStatic("org.w3c.dom.Document")
    MainForm.RootPane.LoadLayout("principal") 'Load the layout file.
    temp = wv1
    we = temp.RunMethod("getEngine",Null)
    wv1.Enabled = True
    wv1.Visible = True
    we.RunMethod("load",Array As Object(startPage))
   

    MainForm.Show
End Sub

Sub wv1_PageFinished (Url As String)
    js.enginePut("doc",we.RunMethod("getDocument",Null))
    js.evalString("var t = doc.body.innerHTML;")
    js.evalString("doc.getElementById('LoginPh').value = 'plant';")
    js.evalString("doc.getElementById('PasswordPh').value = 'plant';")
    js.evalString("doc.getElementById('btnlogin').click();")
   
   
End Sub


Please help me.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
The JScriptEngine doesn't work with web pages, it just allows you to run javascript within a java program.

If you want to interact with a web page you will need to use the java class JSObject (netscape.javascript.JSObject).
 
Upvote 0

Edgardo PuntoCom

Member
Licensed User
Longtime User
The JScriptEngine doesn't work with web pages, it just allows you to run javascript within a java program.

If you want to interact with a web page you will need to use the java class JSObject (netscape.javascript.JSObject).
Thanks

But the code that I have shared works well. Only that the Input is in a nested frame. Then I must first right click and choose Open Frame In New Window
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…