Help about TWebView class. reading something from website.

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

Postby Antonio Linares » Mon Jul 04, 2022 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Horizon » Mon Jul 04, 2022 6: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.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

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

Postby Antonio Linares » Mon Jul 04, 2022 9:09 pm

Dear Hakan,

ok, then please try this:

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Horizon » Mon Jul 04, 2022 9:31 pm

Antonio Linares wrote:Dear Hakan,

ok, then please try this:

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


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


Result:
Code: Select all  Expand view
'{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"jQuery1112018490637981077995":112,"readOnly":false}'


Next try:
Code: Select all  Expand view
JSON.stringify(document.getElementById("dosya_listesi_result"))


Result :
Code: Select all  Expand view
'{}'
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

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

Postby Horizon » Mon Jul 04, 2022 9:40 pm

Hi Antonio,

Can you please try this.
Code: Select all  Expand view
#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
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

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

Postby Antonio Linares » Mon Jul 04, 2022 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Horizon » Tue Jul 05, 2022 6: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.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

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

Postby Horizon » Tue Jul 05, 2022 6:30 am

Hi Antonio,

I have changed my code like this.
Code: Select all  Expand view
 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 view
    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 view
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
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

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

Postby Otto » Tue Jul 05, 2022 7:33 am

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
Otto
 
Posts: 6310
Joined: Fri Oct 07, 2005 7:07 pm

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

Postby Antonio Linares » Tue Jul 05, 2022 7:45 am

Morning Hakan,

This is the code:
Code: Select all  Expand view
#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: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Tue Jul 05, 2022 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42059
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests