FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Help about TWebView class. reading something from website.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 05:41 PM

Please try this from the inspector console:

typeof document.getElementById('dosya_listesi_result' )

or

console.log( typeof document.getElementById( 'dosya_listesi_result' ) )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 06:01 PM
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.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 09:09 PM
Dear Hakan,

ok, then please try this:

Code (fw): Select all Collapse
  aaa := 'document.getElementById("yargiTuru").stringify()'
  oWebView:Eval( "SendToFWH( " + aaa + " )" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 09:31 PM
Antonio Linares wrote:Dear Hakan,

ok, then please try this:

Code (fw): Select all Collapse
  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 (fw): Select all Collapse
Uncaught TypeError: document.getElementById(...).stringify is not a function
    at <anonymous>:1:38


My Next try.
Code (fw): Select all Collapse
JSON.stringify(document.getElementById("yargiTuru"))


Result:
Code (fw): Select all Collapse
'{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"jQuery1112018490637981077995":112,"readOnly":false}'


Next try:
Code (fw): Select all Collapse
JSON.stringify(document.getElementById("dosya_listesi_result"))


Result :
Code (fw): Select all Collapse
'{}'
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 09:40 PM
Hi Antonio,

Can you please try this.
Code (fw): Select all Collapse
#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.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 09:43 PM

Please try this:

document.getElementById('dosya_listesi_result' ).constructor.name

Lets know what class of object it is

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:16 PM

We need to find the way to return an object

Tomorrow we will keep trying it

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:30 PM

I am trying using document.getElementById("example").innerHTML and it works from the console, but fails from Bind...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 10:34 PM

The strange thing is that this code:

oWebView:Eval('SendToFWH( document.getElementById("example") )' )

returns "null"

why ? :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Mon Jul 04, 2022 11:23 PM

Solved :-)

oWebView:Eval( 'window.onload = function () { SendToFWH( document.getElementById("example").innerHTML ) }' )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 06:12 AM
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.06
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 06:30 AM
Hi Antonio,

I have changed my code like this.
Code (fw): Select all Collapse
  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 (fw): Select all Collapse
    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 (fw): Select all Collapse
await ExecuteScriptAsync("document.getElementById('DropDownList').selectedIndex");


Is your code "window.onload" same as this await command?
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 07:33 AM

Hakan,
can't you use a timer and check document.readyState first?

Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 07:45 AM
Morning Hakan,

This is the code:
Code (fw): Select all Collapse
#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...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help about TWebView class. reading something from website.
Posted: Tue Jul 05, 2022 07:50 AM
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...
regards, saludos

Antonio Linares
www.fivetechsoft.com