Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Be notified in end of process
#1
Hi,

I use onnavigationcompletehex event for knowing that web page has finished refreshing a url; a web site.
But now, i have a case in what i can get this way working. In the web site appears a popup saying search is in process, but when finished i don't see  onnavigationcompletehex event being fired.
Hope the code helps to debug this problem.

Code:
local m.clink, m.cscript, m.valor, m.exito, m.finished * browse to main page m.clink = "https://contrataciondelestado.es/wps/portal/" m.clink = m.clink + "!ut/p/b1/jZC7bsMwDEW_qCBFybI1SnIsO0gbPyK31lJ4KIIEeSxFv7" m.clink = m.clink + "-KEaBT1HAjeC4PQQgwvSiVsZxJSfAB4TL_HPbz9-F6mU-" m.clink = m.clink + "3PshPsdpaW9WExcBLpE3pvaxj67IITBHAB6VxyZuhKLRhGpH7ArXsOqviHlT8ns-" m.clink = m.clink + "4FeN6bOXQOMSmrsqNZxk6ks_5E4JbXo-" m.clink = m.clink + "rTjeKIyprkHoteucpjvN7_qGAnvMnBP_k3yEsSOoDC5B6cVpC8FZfz18wRSz_O3Vr-" m.clink = m.clink + "oit29dd64ghCtjBZOAcTlUs1RzF_AuxMNAf/dl4/d5/" m.clink = m.clink + "L2dBISEvZ0FBIS9nQSEh/pw/Z7_AVEQAI930OBRD02JPMTPG21004/" m.clink = m.clink + "act/id=0/p=javax.servlet.include.path_info=QCPjspQCPbusquedaQCPMainBusqueda.jsp" m.finished = .f. thisform.oAntView.object.navigate(m.clink) DO WHILE !m.finished * wait for onnavigationcompletehex that changes m.finished value enddo thisform.oantView.Refresh() m.cscript = "jsfcljs(document.forms[" m.cscript = m.cscript + "'viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1']" m.cscript = m.cscript + ",{'viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:linkFormularioBusqueda':" m.cscript = m.cscript + "'viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:linkFormularioBusqueda'},'')" thisform.oantView.executeScript(m.cscript) m.finished = .f. DO WHILE !m.finished * wait for onnavigationcompletehex that changes m.finished value enddo * From publication date field m.valor = "" thisform.oantviewdocument.RequestElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMinFecAnuncioMAQ2", @m.valor) DO WHILE isnull(m.valor) OR empty(m.valor) thisform.oantviewdocument.SetElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMinFecAnuncioMAQ2", "05-12-2024") thisform.oantviewdocument.RequestElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMinFecAnuncioMAQ2", @m.valor) enddo * To publication date field m.valor = "" thisform.oantviewdocument.RequestElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMaxFecAnuncioMAQ", @m.valor) DO WHILE isnull(m.valor) OR empty(m.valor) thisform.oantviewdocument.SetElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMaxFecAnuncioMAQ", "05-12-2024") thisform.oantviewdocument.RequestElementValueByIdSync("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:textMaxFecAnuncioMAQ", @m.valor) enddo * Begin search m.cscript = "iniciarBusqueda('button1', " m.cscript = m.cscript + 'document.getElementById("viewns_Z7_AVEQAI930OBRD02JPMTPG21004_:form1:button1")' m.cscript = m.cscript + ");" thisform.oantView.executeScript(m.cscript) m.finished = .f. DO WHILE !m.finished * wait for onnavigationcompletehex that changes m.finished value enddo *--- Now, how can i be notified that navigation has being completed? * onnavigationcompletehex seems to not work in this case m.finished = .f. DO WHILE !m.finished * wait for onnavigationcompletehex that changes m.finished value enddo

CYZ
Reply
#2
Hi,

WebView2 has an asynchronous interface and as such having a loop and waiting for an event to be raised... doesn't work, as the windows messages never end up getting processed in your tight loop.

See also: No UI threads in an event and in particular the link in there that goes to Microsoft's explaining about the threading model the control uses.
Also see: Asynchronous versus Synchronous
As a result I tend to use timers to work around the inability of a programming language to deal with asynchronous interfaces.
An example is here: VB6 - Exchange Rates example

However.. that's a real pain to program and makes code somewhat difficult to follow.
So... that's why AntView has a lot of synchronous versions of the original asynchronous API methods.
In your case, instead of using the navigate method, I suggest to use navigateSync instead, as then you can drop all the loops where you are waiting for the navigation to complete.

Hope this helps,
--
Wil
Reply
#3
Fine. I always use synchronous methods.
I'll test all this suggestions.
Thanks

CYZ
Reply
#4
Using navigatesync event fired when end works fine.
Thank you and apologyse for so many questions

CYZ
Reply
#5
Hi Carlos,

Glad to hear it works and not a problem at all, you're welcome.
--
Wil
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)