Android Question Setting text fields on webpage - solved needed v1.42 of WebViewExtras

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Does anyone have an example of setting text fields on a webpage?

I want to go to a webpage and then populate the fields (it's a form webpage) from data I have saved.

I've read a lot of posts about reading them by haven't seen an example of setting them

I will know the field name on the page so this shouldn't be too hard but just unable to locate an example.

Once I populate the fields I have the user will fill in the rest of the fields (because specific to them) and send in the form

Any help or example would be nice

Thanks Bobval
 

Brandsum

Well-Known Member
Licensed User
Try this
B4X:
mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, "document.querySelector('input[name=field-104]').value = 'Some Value';")
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, " document.getElementsByName(""field-55"").value = 'FOB# 123';")

when compiled the ""field-55"" becomes "field-55" same as your 'field-55' I am just using double quotes instead of single

Wish I could let you try the real site (I have uploaded the webpage.txt) which is the source from the page.

But the site is password protected and I don't have the authorization to allow people access.

B4X:
#Region  Activity Attributes
   #FullScreen       : true
   #IncludeTitle   : false
#End Region

Sub Process_Globals

End Sub

Sub Globals
   Private sNYEI_FormsWebsite_Main                                As Panel
   Private    sNYEI_SendText                                       As Button
  
   Private    sNYEI_FormsWebsite_Webview                            As WebView
  
  
   Private mWebViewExtras                                           As WebViewExtras
  
   Private mSendInput                                               As SendInput
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("snyei_forms_website")

'-----------------------------------------------------------------------------------------------------
'  Load the webpage - the log in screen will appear have to manually log in the UserAndPasswordRequired
'  doesn't get triggered   - remember to look into this later
'-----------------------------------------------------------------------------------------------------
'   sNYEI_FormsWebsite_Webview.LoadUrl("http://forms.nyelectricalinspection.com/")
   sNYEI_FormsWebsite_Webview.LoadUrl("http://forms.nyelectricalinspection.com/form/Application/6")

  
   sNYEI_SendText.Color       = Colors.Black
   sNYEI_SendText.TextColor   = Colors.White
  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Public  Sub sNYEI_FormsWebsite_Webview_PageFinished(Url As String)
           Log("PageFinished")  
End Sub

Public  Sub sNYEI_SendText_Click
           Log("SendText")
          
           mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, "document.querySelector('input[name=field-55]').value = 'Some Value';")

          
'           Dim Javascript As StringBuilder
'
'           Javascript.Initialize

'Dim Javascript As String = "document.forms[0]['field-55'].value='" & "robert" & "';"
'
'
'mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, Javascript)
'Sleep(5000)
'mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, "alert(document.forms[0]['field-55'].value);" )

'mWebViewExtras.executeJavascript(sNYEI_FormsWebsite_Webview, "document.querySelector('input[name=field-55]').value = 'Some Value';")

'               Javascript.Append("function setSelectionRange(input, selectionStart, selectionEnd) { If (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); }"                _
 '                            &" else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(True); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart);"   _      
  '                          &" range.select(); } }   function setCaretToPos (input, pos) { setSelectionRange(input, pos, pos); } "       _
   '                       &"setCaretToPos(document.getElementById(""field-104""), 0);"  &"document.querySelector(""input[name=field-104]"").value  = ""username"";")
          
'           mWebViewExtras.executeJavascript(sNYEI


'           mSendInput.SendKeys("FOB-1234")

End Sub
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
just to clarify, did you happen to see the image? stuffing a field works with webviewextras. several suggestions regarding the actual command (including mine) have been given. they may all work. the problem is: they don't (and cannot) work with the 2 url's you show in your project. the field to be stuffed is not found at either of those url's. the field to be stuffed is found at the page whose source you captured and uploaded to the forum as webpage.txt. the only way to see that page is to log in with the appropriate credentials. once you do that, you will see the full fill-in form. that is the page whose fob field i stuffed.

the login page is just another instance of a form. stuff that form first with userid and password, and when you get the full fill-in form, you can worry about stuffing the fob field. actually, no need to worry because we know it can easily be done.
 

Attachments

  • robert.png
    robert.png
    18.8 KB · Views: 139
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Those URLs, bring me to the login page unless I am already logged in then they bring me to the home page and I manually naviagaite to the page I uploaded.

Then once I am at the right page I click a button that calls the routine to set the field
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
a puzzlement. unless the image photoshopped itself, the page you uploaded is stuffable. at least you know it can be done.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am such a moron.

This morning I decided to verify the versions of my libraries.

Turns out I was using v1.40 of WebViews as soon as I switched to v1.42 everything works as nicely.

Sorry to put everyone through this for nothing.

Boy there is a feature the IDE could use (to let you know your downloaded libraries were out of date - LOL like Erel has nothing better to do)

Thanks for everyone that tried to help
 
Upvote 0
Top