Jump to content

IE.au3 - Can't get refreshed HTML after query


 Share

Recommended Posts

Hi everyone,

I have a database whose front-end is IE-based and I am trying to write a piece of code for checking if a client exist and if does update some information.

My problem is that I am not able to get the expected results after doing the query to the database. The page is refreshed with the result but I can see the 'new' HTML from within AutoIT.

This is a simplified code only for doing the query for the client name:

#include <IE.au3>

Local $oIE = _IEAttach("Client database")
Local $oFrame2 = _IEFrameGetObjByName($oIE, "workspace")
Local $oObj = _IEGetObjByName($oFrame2, "ClientId")

;;; Check client name. Empty value as there is an empty form
MsgBox(0, "", _IEFormElementGetValue(_IEGetObjByName($oFrame2, "ClientName")))

;;; Fill the form and send query
_IEFormElementSetValue($oObj, "8091409")
Local $oBtnOK = _IEGetObjByName($oFrame2, "OK")
_IEAction($oBtnOK, "click")
_IELoadWait($oIE)

;;; Check client name again
;;; Should have a value but I still get an empty value
;;; I receive same HTML as before although it is not true
MsgBox(0, "", _IEFormElementGetValue(_IEGetObjByName($oFrame2, "ClientName")))

What am I missing?

Thanks for your support.

Link to comment
Share on other sites

First, I don't expect that the code you provide can run at all since you cannot nest _IE function call because their values are passed byRef.

I also suggest you use a DOM inspector, like DebugBar, to examine they page source at each step to verify what you have to work with.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Also ... some basic error checking would be good too. What if the script is bombing out at the $oIE = _IEAttach() point? You'd never know with the way this script is written. Put in a check to either make sure that $oIE is indeed an object, or examine the @error code that _IEAttach() returns, especially if you're setting Local variables.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Hi Dale,

first of all, thanks for your support.

About my sample code, it do work (although it is irrelevant to my problem): I have the nested _IE calls in the MsgBox and I included these lines to "demonstrate" which is my situation: if I check any object before and after the click I have the same results!

Imagine that instead of a "MsgBox" I have this line: ConsoleWrite(_IEBodyReadHTML($oFrame2))

Well... From within AutoIT I see the same HTML before and after the call when it is not true.

Following your advice, I have installed DebugBar and I was having exactly the same issue until I noticed that after I clicked on the yellow arrow to collapse the DOM tree if I expand again the nodes the right values start to appear!!

So, something it is required to "refresh" the document but I don't know what...

Have I made myself clear? Any ideas?

Thanks.

Fran

Link to comment
Share on other sites

Nothing needs to be done to "refresh the DOM" and DebugBar is NOT having "exactly the same issue". DebugBar needs to be told to go look at the DOM again because it cached what it looked like before. Each time you reference an element directly in the DOM, it reads it anew.

Use the "View Source" icon on the DebugBar toolbar and insure you are looking at the "IE Interpreted Source Code" tab therein.

Dale

also, I get, as expected:

ERROR: _IEFormElementGetValue() called with Const or expression on ByRef-param(s).

MsgBox(0, "", _IEFormElementGetValue(_IEGetObjByName($oFrame2, "ClientName"))

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\IE.au3(1252,45) : REF: definition of _IEFormElementGetValue().

Func _IEFormElementGetValue(ByRef $o_object)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

ERROR: _IEFormElementGetValue() called with Const or expression on ByRef-param(s).

MsgBox(0, "", _IEFormElementGetValue(_IEGetObjByName($oFrame2, "ClientName"))

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\IE.au3(1252,45) : REF: definition of _IEFormElementGetValue().

Func _IEFormElementGetValue(ByRef $o_object)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Hi Dale,

I understand what you say but I am not sure I get what you mean.

You say that "DebugBar needs to be told to go look at the DOM again because it cached what it looked like before". Ok, great, but what about IE.au3? That's my interest!!

I already knew before installing DebugBar that the HTML page was changing but I wasn't getting the current values from within AutoIt.

How do I tell IE.au3 to "go look at the DOM again" because the data has changed????

Thanks again for your kind answers.

Fran.

Link to comment
Share on other sites

Add a loop to wait for th data to populate.

Get the parent object, and then do a loop waiting for the children to be populated:

While $oYourObject.childNodes.length = 0
Wend
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

IE.au3 doesn't cache anything. In my reply above: "Each time you reference an element directly in the DOM, it reads it anew.".

@jdelaney may be correct and it may be a timing issue.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I've also seen some odd behavior on webpages, where dispite the dom object appearing to not change, performing some action causes a new object to be created.

such as, get the $object.uniqueid = x, perform some action, and now (after grabbing the object fresh from the dom) the $object.uniqueid = y

Not sure how prevelent that is, but it's something you need to verify.

In my instance, there is an input box that has no value ($object.value = 0), and then clicking some other object fills in the value, but attempting to get $object.value will still be 0. Grabbing the object again (after the action, and waiting for the data to be populated), allows me to pull $object.value = 'something'.

So what I would do, is grab the uniqueid prior to the action, and loop through grabbing the node until uniqueid changes

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Just realize that it is not indeterminate and neither IE.au3 nor AutoIt nor the DOM do any caching or need to be refreshed. If you reference $oIE.document.some-DOM-node you will get a reference to what is currently active in the DOM when you make the reference. The trick is understanding what is really happening and when elements may be created, destroyed or recreated.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I finally made it work!

As jdelaney perfectly described in his last post, after performing an action, the object is being recreated. However the "trick" of using uniqueId didn't worked for me so I had to find a changing value in the object to identify when the page has been refreshed.

Besides, the only way to "refresh" the object wat to re-attach again each time. This worked for me although maybe is a bit lousy:

#include <IE.au3>

Local $oIE1 = _IEAttach("Client database")
Local $oFrame1 = _IEFrameGetObjByName($oIE1, "workspace")
Local $oForm1 = _IEFormGetObjByName($oFrame1, "frm")
Local $id1 = $oForm1.action

;;; Fill the form and send query
Local $oObj = _IEGetObjByName($oFrame2, "ClientId")
_IEFormElementSetValue($oObj, "8091409")
Local $oBtnOK = _IEGetObjByName($oFrame2, "OK")

_IEAction($oBtnOK, "click")
_IELoadWait($oIE)

Local $exit = False
While not $exit
   Local $oIE2 = _IEAttach("Client database")
   Local $oFrame2 = _IEFrameGetObjByName($oIE2, "workspace")
   Local $oForm2 = _IEFormGetObjByName($oFrame2, "frm")
   Local $id2 = $oForm2.action

   $exit= ($id1 <> $id2) and (StringInStr($id2, "OK_BUTTON") = 0)
WEnd

Thanks everybody for your contributions so far.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...