Everything else that doesn't fall into one of the other PB categories.
-
ricardo
- Addict

- Posts: 2438
- Joined: Fri Apr 25, 2003 7:06 pm
- Location: Argentina
Post
by ricardo »
Hi,
Im just testing WevViewGadget and i tried to do a simple test: write a seacrh ternm in Google and make a search, using javascript.
I tried
Code: Select all
WebViewExecuteScript(0,~"document.querySelector('input[name=\"q\"]').value = \"purebasic\"")
But it does not work.
I am just trying to run this action using javascript:
Code: Select all
document.querySelector('input[name="q"]').value = "ai";
document.querySelector('input[name="btnK"]').click();
Thanks
ARGENTINA WORLD CHAMPION
-
Kiffi
- Addict

- Posts: 1485
- Joined: Tue Mar 02, 2004 1:20 pm
- Location: Amphibios 9
Post
by Kiffi »
You have to wait until the page has loaded completely. Only then can you perform the search.
Code: Select all
EnableExplicit
#Window = 0
#WebViewGadget = 0
Procedure DocumentIsLoaded(JsonParameters.s)
WebViewExecuteScript(#WebViewGadget, ~"document.querySelector('textarea').value = \"purebasic\"")
WebViewExecuteScript(#WebViewGadget, ~"document.querySelector('input[name=\"btnK\"]').click();")
ProcedureReturn UTF8(~"")
EndProcedure
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 1000, 800, "Hello", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebViewGadget(#WebViewGadget, 0, 0, 1000, 800, #PB_WebView_Debug)
BindWebViewCallback(#WebViewGadget, "DocumentIsLoaded", @DocumentIsLoaded())
SetGadgetText(#WebViewGadget, "https://www.google.com/")
WebViewExecuteScript(#WebViewGadget, "document.onreadystatechange = function () {" +
" if (document.readyState == 'interactive') {" +
" DocumentIsLoaded();" +
" }" +
"}")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Hygge
-
ricardo
- Addict

- Posts: 2438
- Joined: Fri Apr 25, 2003 7:06 pm
- Location: Argentina
Post
by ricardo »
Kiffi wrote: Mon Aug 05, 2024 7:23 pm
You have to wait until the page has loaded completely. Only then can you perform the search.
Code: Select all
EnableExplicit
#Window = 0
#WebViewGadget = 0
Procedure DocumentIsLoaded(JsonParameters.s)
WebViewExecuteScript(#WebViewGadget, ~"document.querySelector('textarea').value = \"purebasic\"")
WebViewExecuteScript(#WebViewGadget, ~"document.querySelector('input[name=\"btnK\"]').click();")
ProcedureReturn UTF8(~"")
EndProcedure
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 1000, 800, "Hello", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebViewGadget(#WebViewGadget, 0, 0, 1000, 800, #PB_WebView_Debug)
BindWebViewCallback(#WebViewGadget, "DocumentIsLoaded", @DocumentIsLoaded())
SetGadgetText(#WebViewGadget, "https://www.google.com/")
WebViewExecuteScript(#WebViewGadget, "document.onreadystatechange = function () {" +
" if (document.readyState == 'interactive') {" +
" DocumentIsLoaded();" +
" }" +
"}")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Really thanks. !!!
ARGENTINA WORLD CHAMPION