Help about TWebView class. reading something from website.

User avatar
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.

Post 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' ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Horizon
Posts: 1327
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 5 times

Re: Help about TWebView class. reading something from website.

Post 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'
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
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.

Post by Antonio Linares »

Dear Hakan,

ok, then please try this:

Code: Select all | Expand

 aaa := 'document.getElementById("yargiTuru").stringify()'
  oWebView:Eval( "SendToFWH( " + aaa + " )" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Horizon
Posts: 1327
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 5 times

Re: Help about TWebView class. reading something from website.

Post 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.

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
Horizon
Posts: 1327
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 5 times

Re: Help about TWebView class. reading something from website.

Post 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
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
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.

Post by Antonio Linares »

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
User avatar
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.

Post by Antonio Linares »

We need to find the way to return an object

Tomorrow we will keep trying it
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
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.

Post by Antonio Linares »

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
User avatar
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.

Post by Antonio Linares »

The strange thing is that this code:

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

returns "null"

why ? :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
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.

Post by Antonio Linares »

Solved :-)

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

Antonio Linares
www.fivetechsoft.com
Horizon
Posts: 1327
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 5 times

Re: Help about TWebView class. reading something from website.

Post 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.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
Posts: 1327
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 5 times

Re: Help about TWebView class. reading something from website.

Post 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?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
User avatar
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.

Post by Otto »

Hakan,
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
********************************************************************
User avatar
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.

Post 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...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
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.

Post 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.22

I am going to ask Steffen...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply