I tested this sample successfully. May be this can help someone:
- Code: Select all Expand view
#include "FiveWin.ch"
static oWebView
function Main()
local oWnd, cFile
DEFINE WINDOW oWnd TITLE "Consulta de Comprobantes" MENU BuildMenu()
oWnd:Center()
oWebView = TWebView():New(1, oWnd:hWnd )
oWebView:Navigate( "https://myefacts.com/test/")
oWebView:SetSize( 1000, 700 )
oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
oWebView:Bind( "SendToFWH" )
oWebView:bOnBind = { | cJson, cCalls | cFile:="c:\temp\respuesta.json" , StrFile( cJson, cFile), alert(cFile) }
Sleep( 400 )
oWebView:InjectJavascript( SetScript() )
oWebView:Eval( "MyScript()" )
ACTIVATE WINDOW oWnd CENTER ;
oWebView:Destroy()
return nil
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "Source." ACTION oWebView:Eval( "SendToFWH( document.body.outerHTML )" )
MENUITEM "Load ." ACTION (oWebView:Eval( "MyScript()" ), oWebView:Eval( "alert( 'asignado '+document.getElementById('num_ruc').value )" ) )
MENUITEM "About ." ACTION MsgAbout()
ENDMENU
return oMenu
//---------------------
function SetScript()
local cHtml
TEXT INTO cHtml
function MyScript() {
document.getElementById("num_ruc").value = '20123456781' ;
}
ENDTEXT
return cHtml
Unfortunally, i can not make it work with this public page:
- Code: Select all Expand view
oWebView:Navigate( "https://e-consulta.sunat.gob.pe/ol-ti-itconsvalicpe/ConsValiCpe.htm" )
....
The page contains elements with the same name.
Maybe, i think, the google-recaptcha it contains is avoiding javascript injection.
If someone can help, welcome!