Page 2 of 3
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 5:41 pm
by Antonio Linares
Please try this from the inspector console:
typeof document.getElementById('dosya_listesi_result' )
or
console.log( typeof document.getElementById( 'dosya_listesi_result' ) )
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 6:01 pm
by Horizon
Antonio Linares wrote:Please try this from the inspector console:
typeof document.getElementById('dosya_listesi_result' )
or
console.log( typeof document.getElementById( 'dosya_listesi_result' ) )
Hi Antonio,
The result is 'object'
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 9:09 pm
by Antonio Linares
Dear Hakan,
ok, then please try this:
Code: Select all | Expand
aaa := 'document.getElementById("yargiTuru").stringify()'
oWebView:Eval( "SendToFWH( " + aaa + " )" )
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 9:31 pm
by Horizon
Antonio Linares wrote:Dear Hakan,
ok, then please try this:
Code: Select all | Expand
aaa := 'document.getElementById("yargiTuru").stringify()'
oWebView:Eval( "SendToFWH( " + aaa + " )" )
There is not any show. but when I write to console. This error is given.
Code: Select all | Expand
Uncaught TypeError: document.getElementById(...).stringify is not a function
at <anonymous>:1:38
My Next try.
Result:
Code: Select all | Expand
'{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"jQuery1112018490637981077995":112,"readOnly":false}'
Next try:
Code: Select all | Expand
JSON.stringify(document.getElementById("dosya_listesi_result"))
Result :
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 9:40 pm
by Horizon
Hi Antonio,
Can you please try this.
Code: Select all | Expand
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWebView := TWebView():New()
oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
oWebView:Bind( "SendToFWH" )
oWebView:Navigate( "https://datatables.net/examples/data_sources/js_array" )
// Sleep( 400 )
sysWait(6)
aaa := "document.getElementById('example' )"
oWebView:Eval( 'SendToFWH( First : '+aaa+ ' )' )
oWebView:Eval('console.log( '+aaa+' )')
aaa := 'JSON.stringify(document.getElementById("example"))'
oWebView:Eval( 'SendToFWH( Second : '+aaa+ ' )' )
oWebView:Eval('console.log( '+aaa+' )')
oWebView:Run()
oWebView:Destroy()
return nil
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 9:43 pm
by Antonio Linares
Please try this:
document.getElementById('dosya_listesi_result' ).constructor.name
Lets know what class of object it is
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:16 pm
by Antonio Linares
We need to find the way to return an object
Tomorrow we will keep trying it
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:30 pm
by Antonio Linares
I am trying using document.getElementById("example").innerHTML and it works from the console, but fails from Bind...
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:34 pm
by Antonio Linares
The strange thing is that this code:
oWebView:Eval('SendToFWH( document.getElementById("example") )' )
returns "null"
why ?

Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 11:23 pm
by Antonio Linares
Solved

oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 6:12 am
by Horizon
Antonio Linares wrote:Solved

oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )
Goodmorning Antonio,
Can you please share full code in sample app? When I insert this line, there is not any messagebox anymore.
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 6:30 am
by Horizon
Hi Antonio,
I have changed my code like this.
Code: Select all | Expand
aaa := "document.getElementById('dosya_listesi_result' ).innerHTML"
oWebView:Eval( 'SendToFWH( '+aaa+ ' )' )
It displays the all record in table.
But your code is more readable than mine.
Code: Select all | Expand
oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("dosya_listesi_result").innerHTML ) }' )
There is not any showmessage box.
I want to ask something. We need sleep() function to wait for windows loading web site code. But every customer has different internet speed. We should change seconds every customer in sleep function. I have seen a different "await" command in stackoverflow.com.
Code: Select all | Expand
await ExecuteScriptAsync("document.getElementById('DropDownList').selectedIndex");
Is your code "window.onload" same as this await command?
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 7:33 am
by Otto
Hakan,
can't you use a timer and check document.readyState first?
Best regards,
Otto
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 7:45 am
by Antonio Linares
Morning Hakan,
This is the code:
Code: Select all | Expand
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWebView := TWebView():New(), aaa
oWebView:bOnBind = { | cJson, nCalls | MsgInfo( cJson, nCalls ) }
oWebView:Bind( "SendToFWH" )
oWebView:Navigate( "https://datatables.net/examples/data_sources/js_array" )
Sleep( 200 )
oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )
oWebView:Run()
oWebView:Destroy()
return nil
Going to check your await command...
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 7:50 am
by Antonio Linares
Hakan,
ExecuteScriptAsync() seems to be a method of WebView2 that has not been implemented in webview.dll yet
https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.wpf.webview2.executescriptasync?view=webview2-dotnet-1.0.1245.22I am going to ask Steffen...