Jump to content
Sign in to follow this  
imacleod

GetElementsByName error

Recommended Posts

imacleod

I hava script that runs OK through many loops but seems incapable of completing a full run of 2000+.

There's a loop where it waits for a button "SUB" to appear on a page; here it loops twice:

0087: 0-0:                     WinWait("Confirm Add/Update/Extend Action - Windows Internet Explorer")
0088: 0-0:                     Local $oIEconfirm = _IEAttach("Confirm Add/Update/Extend Action")
0090: 0-0:                     Local $oConfirm = _IEGetObjByName($oIEconfirm, "action")
0091: 0-1:                     _IEAction($oConfirm, "click")
0092: 0-0:                     Sleep(500)
0094: 0-0:                     Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: SUB, Index: 0)
0095: 7-0:                     While @error
0096: 7-0:                         Sleep(250)
0097: 0-0:                         Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: SUB, Index: 0)
0098: 7-0:                     WEnd
0096: 7-0:                         Sleep(250)
0097: 0-0:                         Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
0098: 0-1:                     WEnd
0099: 0-1:                     _IEAction($oContinue, "click")
0102: 0-0:                     FileWriteLine($sLogFileName, $aCDSIDs[$i] & " " & _NowTime())
0103: 0-0:                     ExitLoop

eventually, almost invariably, it gets to someting like this:

0094: 0-0:                     Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
--> IE.au3 V2.4-0 Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: SUB, Index: 0)
0095: 7-0:                     While @error
0096: 7-0:                         Sleep(250)
0097: 0-0:                         Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
C:\Program Files (x86)\AutoIt3\Include\IE.au3 (2361) : ==> The requested action with this object has failed.:
If IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)) Then
If IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)^ ERROR
->12:27:14 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 817.276

That was after having completed 149 cycles.

The AutoIt version I'm running is a bit old:, Starting AutoIt3Wrapper v.2.1.0.33    Environment(Language:0409  Keyboard:00000809  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)

Offically, I'm internally constrained in what I can use, so I don't want to go through the upgrade process unless I need to.

As always, any pointers appreciated,

Iain

Share this post


Link to post
Share on other sites
Valiante

Hi Iain,

Any chance we can see the script please?

Rgds,

Val.

Share this post


Link to post
Share on other sites
imacleod

Here's the main loop:

Else
    ; Read in lines of comma seperated IDs until the EOF is reached
    While 1
        Local $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        Global $aIDs = StringSplit($line, $DELIM)
        For $i = 1 To $aIDs[0]
            ;Wait until the tab titled '**** LIST page' exists
            WinWait("**** LIST page - Windows Internet Explorer")
            ;attach to the TAB with '**** LIST page' as title
            Local $oIE = _IEAttach("**** LIST page")

            ;"ACQUSER" is the name of the ID input box, get a reference for it
            Global $oText = _IEGetObjByName($oIE, "ACQUSER")
            ; Assign input focus to the field and then send the text string
            _IEAction($oText, "focus")
            _IEFormElementSetValue($oText, $aIDs[$i])
            ;"ACQUIRE" is the name of the "Update" button, get a reference for it
            Local $oUpdate = _IEGetObjByName($oIE, "ACQUIRE")
            _IEAction($oUpdate, "click")
            ;Page is redrawn. If the ID is invalid a different page will display
            ; - check the URL of that page for the ID that was causing the issue
            While 1
                If WinExists("**** - Update/Extend This Userid - Windows Internet Explorer") Then
                    Local $oIEextend = _IEAttach("**** - Update/Extend This Userid")
                    ;Define an object containing the HTML from the page
                    Local $oPage = _IEDocReadHTML($oIEextend)
                    ; Change the 'dev.checked' variable check so that it does not trigger a 'help' page
                    Local $oPage_u = StringRegExpReplace($oPage, "dev\.checked", "devX\.checked")
                    ;Display the page with the doctored variable
                    _IEDocWriteHTML($oIEextend, $oPage_u)
                    ;"UPDATE" is the name of the "Submit request" button
                    Local $oSubmit = _IEGetObjByName($oIEextend, "UPDATE")
                    _IEAction($oSubmit, "click")

                    ;Page is redrawn
                    WinWait("Confirm Add/Update/Extend Action - Windows Internet Explorer")
                    Local $oIEconfirm = _IEAttach("Confirm Add/Update/Extend Action")
                    ;Click the "Confirm" button...
                    Local $oConfirm = _IEGetObjByName($oIEconfirm, "action")
                    _IEAction($oConfirm, "click")
                    Sleep(500)
                    ; ...and "Continue" buttons
                    Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
                    While @error
                        Sleep(250)
                        Local $oContinue = _IEGetObjByName($oIEconfirm, "SUB")
                        ; will create "Warning from function _IEGetObjByName, $_IEStatus_NoMatch (Name: SUB, Index: 0)" in console if run in debug
                    WEnd
                    _IEAction($oContinue, "click")

                    ;log the ID as processed
                    FileWriteLine($sLogFileName, $aIDs[$i] & " " & _NowTime())
                    ExitLoop
                ElseIf WinExists("**** - Userid Sponsorship - Windows Internet Explorer") Then
                    ;Invalid ID in list, sleep to make message readable
                    Sleep(1000)
                    ; store in array for reference
                    _ArrayAdd($aInvalidIDs, $aIDs[$i])
                    ;Open a new '**** LIST page"
                    _IENavigate($oIE, "http://****")

                    ;log the ID as having issues
                    FileWriteLine($sLogFileName, $aIDs[$i] & " issues with ID")
                    ExitLoop
                Else
                    Sleep(200)
                EndIf
            WEnd
        Next
    WEnd
EndIf

 

This is not my day job so don't laugh;-)

BTW, the _IEDocReadHTML and _IEDocWriteHTML results in the content being displayed twice on the page, but that does not matter to me, it achieved not triggering some javascript. I only noticed when I watched the script run on a low page zoom!

Edited by imacleod

Share this post


Link to post
Share on other sites
Valiante

Hi Iain,

It would be helpful to me and others reading this thread if you could kindly edit your post and enclose the code in [autoit] tags please.

Rgds,

Val.

Share this post


Link to post
Share on other sites
Valiante

Perfect thanks. I'll have a look through it and see if I spot anything obvious, but it's tricky without access to the page it's manipulating.  Hope you understand. :)

With a bit of luck I or one of the experts here will spot something and be able to help.

Share this post


Link to post
Share on other sites
imacleod

PS.

Not sure if this is relevent but, another odd thing has happened a couple of times. If I have the script open in SciTE and run it with debug on, a couple of times in the console it looks like it's crashed, e.g.:

0074: 0-0:                 If WinExists("****- Update/Extend This Userid - Windows Internet Explorer") Then
0075: 0-0:                     Local $oIEextend = _IEAttach("**** - Update/Extend This Userid")
0077: 0-0:                     Local $oPage = _IEDocReadHTML($oIEextend)
0079: 0-0:                     Local $oPage_u = StringRegExpReplace($oPage, "dev.checked", "devX.checked")
0081: 0-0:                     _IEDocWriteHTML($oIEextend, $oPage_u)
C:\Program Files (x86)\AutoIt3\Include\IE.au3 (611) : ==> The requested action with this object has failed.:
WEnd
WEnd^ ERROR
->15:26:28 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 315.769

However the script keeps IE going for quite some time; it ran for over an hour after producing the above...

Share this post


Link to post
Share on other sites
imacleod

There are multiple random, non-repeatable, error messages, e.g. (OCR'd, so may have some minor errors in the text that I've missed):

Line 2034 (File “C:\Program Files (x86)\AutoIt3\Include\IE.au3”):
Return SetError(S_IEStatus_Success, 0,
So_object.document.documentElement.outerHTML)
Return SetError(S_IEStatus_Success, 0,
So.object.document.documentElement.outerHTMV ERROR
Error The requested action with this object has failed.

Line1299 (File “C:\Program Files (x86)\Autolt3\Include\IE.au3"):
If String($o..object.type) = "file” Then
If String($o_object.type^ ERROR

Error: The requested action with this object has failed.

Line 2361 (File “C:\Program Files (x86)\Autolt3\lnclude\IE.au3’):
If
IsObj($o_object.document.GetElementsByName($s_Id).item($i_index))
Then
If
IsObj($o_object.document.GetElementsByName($s_Id).item($i_index)^
ERROR
Error The requested action with this object has failed.

Some of these stall, or fully crash, the interface the script is driving, some have no effect.

I'm begining to wonder if the issues are being caused by loss of focus. The script launches a new IE instance, and in the main, it can be left to run and I get on with other things. However, sometimes it battles for focus, even though the other browser instance does not have tabs with relevent names...

I guess I have no real option but to upgrade the version I'm using and see what issues remain...

Share this post


Link to post
Share on other sites
imacleod

I've loaded 3.3.10.2 and so far, so good; no error messages, as yet.

I'm still having focus issues, unless the AutoIt instance of IE is minimised, in which case it runs OK, i.e. it does not grab focus from the other IE instance that I'm working in. Sometimes it grabs focus even when minimised, it flashes away on the bar; not clear to me what's triggering it.

Am I doing someting wrong here?:

;Wait until the tab titled '**** LIST page' exists
WinWait("**** LIST page - Windows Internet Explorer")
;attach to the TAB with '**** LIST page' as title
Local $oIE = _IEAttach("**** LIST page")
;"ACQUSER" is the name of the ID input box, get a reference for it
Global $oText = _IEGetObjByName($oIE, "ACQUSER")
; Assign input focus to the field and then send the text string
_IEAction($oText, "focus")
_IEFormElementSetValue($oText, $aIDs[$i])
;"ACQUIRE" is the name of the "Update" button, get a reference for it
Local $oUpdate = _IEGetObjByName($oIE, "ACQUIRE")
_IEAction($oUpdate, "click")
Edited by imacleod

Share this post


Link to post
Share on other sites
Danp2

IDK. You have stated what you are trying to achieve and what isn't working. :ermm:

Can you explain why you are using WinWait and WinExists as opposed to the _IE* functions?

Also, once you attach to a specific tab, you shouldn't need to continue calling _IEAttach unless you are switching to a new tab / window.

Share this post


Link to post
Share on other sites
imacleod

When I pulled this together last year there were issues with the _IE functions and I was guided to the existing setup by other users on here, and trial and error. Those issues may have been resolved now, however, given my limited expertise I'm relunctant to change more than I need to. (See '?do=embed' frameborder='0' data-embedContent>> for background).

The script automates the processing of IDs, though a web interface over which I have no influence. The title of the IE instance and tab change with each of half-a-dozen or so screens that I need to cycle through, hence the _IEAttach

The script launches a new IE instance using ShellExecute("iexplore", "http://host:app") then cycles through the above loop.

Since upgrading theAutoIt version, execution stability is greatly improved; I have my suspicions that the remaining issues are focus related, it keeps stealing focus from a different IE instance where I'm trying to do other, completely unrelated, work.

There are ~3000 IDs and the WAN latency and server response time mean that a "run" can take around 8 hours; I'm going to try running it from a spare PC and/or over a VPN from home tonight and see if it's stable enough to make it through without falling over if it's left in peace (which would go a long way to proving that focus loss is my issue)...

Share this post


Link to post
Share on other sites
Danp2

Now that you are running the updated version of AutoIt, I would suggest that you try using _IECreate again.

If you are only using a single instance of IE, then you don't need to keep calling _IEAttach even if the title changes. The existing reference contained in $oIE should still be valid for the given tab.

Share this post


Link to post
Share on other sites
imacleod

OK, I'll try that.

On a slightly different subject, can anyone suggest why when running the script in debug mode a cycle takes 9 seconds, whilst running a compiled version of the script takes only 3 seconds? Is that kind of difference normal for, what I imagine is, a relatively small and straightforward script?

Share this post


Link to post
Share on other sites
imacleod

If you are only using a single instance of IE, then you don't need to keep calling _IEAttach even if the title changes. The existing reference contained in $oIE should still be valid for the given tab.

 

Ideally this stuff would run in the background in it's own tab and allow the same IE instance to be used for other work. I don't mind if it has its own instance, if that's easiest/best, however it needs to be robust; at the moment, it looks like the focus clashes are what's causing the runs to fail...

Share this post


Link to post
Share on other sites
imacleod

BTW, since upgrading the AutoIt version the script no longer works when screen locked...

I also happened to notice that I've got three instance of the executable running even though IE has been closed down; I can kill them in Task Manager but I guess I missed some trick there. The issue may go away when I try _IECreate again...

Edited by imacleod

Share this post


Link to post
Share on other sites
imacleod

OK,

I've tried _IECreate and there are some issues, including focus. Before I invest the time to try and sort them out, can I please have some guidance around the "best" way to go about things.

This script needs to run a for a long time - over two hours - and consequently I need it to be:

  1. Above all else, be robust: with ~3000 cycles in a run it's a PITA when it keeps failing (as far as I can tell these failures are due to focus issues resulting from other concurrent IE activities on the PC)
  2. Be capable of running under a locked screen
  3. Either
  • Play nicely with other IE(8) instances and/or tabs (so the PC can be used for other work)
  • or
  • If needs-be, run on a dedicated PC/out of office hours (not a great option)

Given this is scripting tool I would have thought that "silent running" would be a common requirement, however achieving it seems to be a challenge (for me). There are many ways to skin a cat, and I don't know the full pros and cons of IECreate (doesn't seem to like other versus's ShellExecute...or even whether there's a better AutoIt function available.

I only know what I've gleaned from the forum, the help files and input from the various people who have helped along the way...and, as it's only used on a quarterly basis, I've probably forgotten half of all the above in the rather long time I've been playing with this...

PS.

My _IECreate version seems to be behaving itself a lot better now, even when using other tabs in the same instance. I'd still appreciate some confirmation that's the best way to go...

Edited by imacleod

Share this post


Link to post
Share on other sites
Danp2

Have you considered using an embedded IE object instead the traditional one? This may help avoid some of the issues you are experiencing.

Here's some code from a script where I do this:

; Create embedded IE object
    $oIE = _IECreateEmbedded ()

    ; Dummy GUI
    GUICreate("Dummy", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2)
    GUICtrlCreateObj($oIE, 10, 40, 600, 360)

    ; Open instance of website
    _IENavigate ($oIE, $Url)

Share this post


Link to post
Share on other sites
imacleod

Hi Dan,

No, I've not tried that; do you think that would help with the focus issues?

BTW, when using _IECreate it's far from reliable: one run processed 362 items, another 564 before stopping on different screens - my best guess is that it lost focus.

Share this post


Link to post
Share on other sites
Danp2

It may help, especially since you want the script to run in the background. You won't know until you try. ;-)

You could try adding some logging / debugging code to your script to allow you to determine where it is failing and under what conditions.

Share this post


Link to post
Share on other sites
imacleod

I've had a quick hack at it but limited success. It gets so far but then fails to click a button, where _IEAction($oUpdate, "click") used to do the trick.With all the Window and tab labels gone it's changed all the logic in the script; it's not a trivial exercise to test this out, especially as I'm not the most proficient programmer in the first place.

I don't want to sound unappreciative, but I wish I had some confidence this would solve the issues rather than expending time and effort just to suck it and see...

BTW, I'm out of office until next Tuesday now. I may not have much opportunity to check up on this between now an then.

Share this post


Link to post
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
Sign in to follow this  

×