Set text to web textbox
Set text to web textbox
hello
Is it possible to set strings on the textbox in the web page loaded in the webviewgadget?
actually, I want to detect the textbox of the web page and put a string on it. Is this possible by webview control?
Is it possible to set strings on the textbox in the web page loaded in the webviewgadget?
actually, I want to detect the textbox of the web page and put a string on it. Is this possible by webview control?
Re: Set text to web textbox
How about the WebViewExecuteScript(#Gadget, JavaScript$) function?
SOmething like:
I didn't have time to fully test it, but something like that should get you started. 
SOmething like:
Code: Select all
WebViewExecuteScript(#MyWebView, "document.getElementById('textbox-id').value = 'new text';")

Re: Set text to web textbox
thank you
Is there a function that displays the name or ID of the controls on the web page?
Because I don't know its ID.
Is there a function that displays the name or ID of the controls on the web page?
Because I don't know its ID.
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Set text to web textbox
Is it always the same page or a different one every time? If always the same you can look it up in your favorite browser by pressing f12.punak wrote: Sat Aug 31, 2024 6:03 am thank you
Is there a function that displays the name or ID of the controls on the web page?
Because I don't know its ID.
You can also enumerate all text fields with document.getElementsByTagName or document.querySelectorAll
bye,
Daniel
Daniel
Re: Set text to web textbox
Can you give an example that returns the id or name of the web controls? Especially the inputs or text boxes...
I tried a lot but my problem still persists
I tried a lot but my problem still persists

Re: Set text to web textbox
Please help me, believe me, I couldn't write by myself, otherwise I wouldn't have asked you.
I don't know JavaScript syntax, just a piece of code that returns the ID or name of the controls on the screen would be great. I want to put my own text on the inputs of a web page whose IDs I don't know
I don't know JavaScript syntax, just a piece of code that returns the ID or name of the controls on the screen would be great. I want to put my own text on the inputs of a web page whose IDs I don't know
Re: Set text to web textbox
May be you can ask ChatGPT for Javascript, it works properly. Using Quin command, I can successfully set a text in a web input. Here is an example to query a content of an input.
And the HTML file
Code: Select all
Procedure TextContentCallback(JsonParameters$)
Debug #PB_Compiler_Procedure +": " + JsonParameters$
Dim Parameters.s(0)
; Extract the parameters from the JSON
ParseJSON(0, JsonParameters$)
ExtractJSONArray(JSONValue(0), Parameters())
Debug "Parameter 1: " + Parameters(0)
ProcedureReturn UTF8("")
EndProcedure
OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu | #PB_Window_Invisible)
WebViewGadget(0, 0, 0, 400, 400)
SetGadgetText(0, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
; Show the window once the webview has been fully loaded
HideWindow(0, #False)
WebViewExecuteScript(0, "document.getElementById('my-input').value = 'new text';")
BindWebViewCallback(0, "getTextContent", @TextContentCallback())
WebViewExecuteScript(0, "getTextContent(document.getElementById('my-input').value);")
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Code: Select all
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="webview.css">
</head>
<body>
<input type="text" id="my-input" name="name" required minlength="4" maxlength="8" size="10" />
<script>
</script>
</body>
</html>
Re: Set text to web textbox
Thank you very much Fred.
This is a great example when I've built a web page myself and know what ID input is.
I want to find the input IDs of a site loaded in the webview control and fill them.
This is my main problem.

This is a great example when I've built a web page myself and know what ID input is.
I want to find the input IDs of a site loaded in the webview control and fill them.
This is my main problem.
Re: Set text to web textbox
You can try this one to get the full HTML page, so you can parse it with the XML lib and get the ID you want:
Code: Select all
Procedure TextContentCallback(JsonParameters$)
Debug #PB_Compiler_Procedure +": " + JsonParameters$
Dim Parameters.s(0)
; Extract the parameters from the JSON
ParseJSON(0, JsonParameters$)
ExtractJSONArray(JSONValue(0), Parameters())
Debug "Parameter 1: " + Parameters(0)
ProcedureReturn UTF8("")
EndProcedure
Procedure PageLoadedCallback(JsonParameters$)
WebViewExecuteScript(0, "document.getElementById('my-input').value = 'new text';")
BindWebViewCallback(0, "getAsString", @TextContentCallback())
WebViewExecuteScript(0, "getAsString(document.getElementById('my-input').value);")
WebViewExecuteScript(0, "getAsString(document.documentElement.innerHTML);")
ProcedureReturn UTF8("")
EndProcedure
OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu | #PB_Window_Invisible)
WebViewGadget(0, 0, 0, 400, 400, #PB_WebView_Debug)
SetGadgetText(0, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
; Show the window once the webview has been fully loaded
HideWindow(0, #False)
; When loading a page, we need to wait for the load event before accessing the DOM
;
BindWebViewCallback(0, "pageLoaded", @PageLoadedCallback())
WebViewExecuteScript(0, "window.addEventListener('load', function () {pageLoaded(); })");
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow[/code]
Re: Set text to web textbox
Load the page in your browser (i.e: Chrome), then push F12 and you can see (visually) the ID of the fields you are searching for.punak wrote: Fri Sep 13, 2024 3:05 pm I want to find the input IDs of a site loaded in the webview control and fill them.
After that, you can use the code on this thread to fill it on your program.
Re: Set text to web textbox
Thanks Fred, I haven't got the result yet, but maybe your codes will make me successful.
@Caronte3D : I did what you said and it showed me these. Which one is ID?
@Caronte3D : I did what you said and it showed me these. Which one is ID?
Code: Select all
<input _ngcontent-ial-c516="" type="text" autocomplete="off" formcontrolname="UserName" autofocus="" placeholder="uname" class="form-control myInput ng-dirty ng-valid ng-touched" style="direction: ltr; border-radius: 50px;">
Re: Set text to web textbox
Oh boy, that's some not very pretty HTML...
You could maybe use document.getElementsByClassName and use what it says for class.
You could maybe use document.getElementsByClassName and use what it says for class.
Re: Set text to web textbox
@Quin , Can you give a codes example please?