Help about TWebView class. reading something from website.
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
Please try this from the inspector console:
typeof document.getElementById('dosya_listesi_result' )
or
console.log( typeof document.getElementById( 'dosya_listesi_result' ) )
typeof document.getElementById('dosya_listesi_result' )
or
console.log( typeof document.getElementById( 'dosya_listesi_result' ) )
Re: Help about TWebView class. reading something from website.
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'
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
Dear Hakan,
ok, then please try this:
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.
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.
Code: Select all | Expand
JSON.stringify(document.getElementById("yargiTuru"))
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 :
Code: Select all | Expand
'{}'
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Re: Help about TWebView class. reading something from website.
Hi Antonio,
Can you please try this.
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
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
Please try this:
document.getElementById('dosya_listesi_result' ).constructor.name
Lets know what class of object it is
document.getElementById('dosya_listesi_result' ).constructor.name
Lets know what class of object it is
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
We need to find the way to return an object
Tomorrow we will keep trying it
Tomorrow we will keep trying it
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
I am trying using document.getElementById("example").innerHTML and it works from the console, but fails from Bind...
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
The strange thing is that this code:
oWebView:Eval('SendToFWH( document.getElementById("example") )' )
returns "null"
why ?
oWebView:Eval('SendToFWH( document.getElementById("example") )' )
returns "null"
why ?

- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
Solved 
oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )

oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )
Re: Help about TWebView class. reading something from website.
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.
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Re: Help about TWebView class. reading something from website.
Hi Antonio,
I have changed my code like this.
It displays the all record in table.
But your code is more readable than mine.
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.
Is your code "window.onload" same as this await command?
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?
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
- Otto
- Posts: 6413
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 27 times
- Been thanked: 2 times
- Contact:
Re: Help about TWebView class. reading something from website.
Hakan,
can't you use a timer and check document.readyState first?
Best regards,
Otto
can't you use a timer and check document.readyState first?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
Morning Hakan,
This is the code:
Going to check your await command...
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...
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
Re: Help about TWebView class. reading something from website.
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.22
I am going to ask Steffen...
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.22
I am going to ask Steffen...