izis89

Object problem. Error The requested action with this object has failed

14 posts in this topic

#1 ·  Posted

Hello,

I am writing script that would go through list and for each entry would gather some data from Web Page.

The problem is that at the same list entry script crashes and gives an error "The requested action with this object has failed"

This is the example of the code that at least for me crashes every time exactly after looping 40 times with the same error. It seems that script crashes after certain number of function calls has been made.

#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <Excel.au3>
#include <Word.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <ColorConstants.au3>
#include <GuiTab.au3>

Local $SearchButton
For $i = 1 to 1000
    Local $oIEObject = _IECreate("https://www.google.com", 1)

    _IELoadWait($oIEObject, 100)

    $TxtField = _IEGetObjById($oIEObject, "lst-ib")
    $TxtField.value = "lalala"

    $SearchButton = _IEGetObjByName($oIEObject,"btnK")

    _IEAction($SearchButton, "focus")
    _IEAction($SearchButton, "click")
    _IELoadWait($oIEObject, 1000, 10000)

    $oIEObject = ""
    WinClose ("lalala")
    ConsoleWrite ("Counter: " & "    " & $i & @CRLF)
Next

I tried to remove every library except IE.au3 and it passes 40 mark but I guess at some point it would crash anyway. However this is not an option since I need these libraries for code to work.

Does anyone of you has any idea why that happens and is there any way to fix it? I tried searching online without any luck.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello @izis89 and welcome :)

The problem is that you're not checking if the functions that you are using are returning correct values or not.

It's the same problem as if you write a program that ask the user to select "1" or "2" but the user put "3" instead and the program crashes because it was unexpected.

Checking that the user only select 1 or 2 is called foolproof coding and that's the problem with your code, you're not doing it :D

Also at the end of your code you need to use IEQuit to delete the object created by IECreate. Using $oIEObject = "" is a really bad way to do it ;)

Here is a corrected version of your code. Try it out:

#include <IE.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <Excel.au3>
#include <Word.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <FileConstants.au3>
#include <Date.au3>
#include <ColorConstants.au3>
#include <GuiTab.au3>

Local $SearchButton

For $i = 1 To 1000

    Local $oIEObject = _IECreate("https://www.google.com")
    If @error Then
        MsgBox("", "_IECreate failed", "Error code: " & @error)
        Exit
    EndIf

    If IsObj($oIEObject) Then

        _IELoadWait($oIEObject, 100)
        If @error Then
            MsgBox("", "_IECreate failed", "Error code: " & @error)
            Exit
        EndIf

        $TxtField = _IEGetObjById($oIEObject, "lst-ib")
        If @error Then
            MsgBox("", "_IEGetObjById failed", "Error code: " & @error)
            Exit
        EndIf

        If IsObj($TxtField) Then

            $TxtField.value = "lalala"

        Else

            MsgBox("", "Error", "No $TxtField is existing")
            Exit

        EndIf

        $SearchButton = _IEGetObjByName($oIEObject, "btnK")
        If @error Then
            MsgBox("", "_IEGetObjByName failed", "Error code: " & @error)
            Exit
        EndIf

        If IsObj($SearchButton) Then

            _IEAction($SearchButton, "focus")
            If @error Then
                MsgBox("", "_IEAction focus failed", "Error code: " & @error)
                Exit
            EndIf

            _IEAction($SearchButton, "click")
            If @error Then
                MsgBox("", "_IEAction click failed", "Error code: " & @error)
                Exit
            EndIf

            _IELoadWait($oIEObject, 1000, 10000)
            If @error Then
                MsgBox("", "_IELoadWait failed", "Error code: " & @error)
                Exit
            EndIf

        Else

            MsgBox("", "Error", "No $SearchButton is existing")
            Exit

        EndIf

        _IEQuit($oIEObject)
        If @error Then
            MsgBox("", "_IEQuit failed", "Error code: " & @error)
            Exit
        EndIf

        ConsoleWrite("Counter: " & "    " & $i & @CRLF)

    Else

        MsgBox("", "Error", "No $oIEObject is existing")
        Exit

    EndIf

Next

PS : avoid using _IECreate("xxx", 1) as it will try to attach to an existing window. Use _IECreate("xxx") instead.

Edited by Neutro

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hello @Neutro

Thank you very much for the input. This was the simplified version of the code that was meant to represent the problem. I know that I have to and check returned values when coding. 

However this did not solved the issue because if the code would work, then it would just give an error and then exit the script after looping the same number of times anyway.

Also, your suggested version also crashed because the script critically fails before returning any value - in the middle of a freaking function - out of the thin air :D It just blows my mind. Try running both versions couple of times by yourself, I think you will be surprised. Different versions will loop different number of times but the number of loops passed will stay the same before crashing.

It seems that IE object ($oObject variable in IE.au3 library functions) is getting destroyed/gone/lost in the middle of the run and that is why critical error occurs.

I tried running my version on the different computer. It crashed after looping 46 times now. EACH TIME I RAN IT. Your version crashed after running 42 loops. Also - EACH TIME I RAN IT. What the hell, guys? :D

Maybe it is some kind of dedicated memory for process filling up or other systemic issue?

So... Are there any other suggestions? I am desperate at this point... 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I just ran my version of the script for 100 loops with 0 problem:

Counter:     1
Counter:     2
Counter:     3
Counter:     4
Counter:     5
Counter:     6
Counter:     7
Counter:     8
Counter:     9
Counter:     10
Counter:     11
Counter:     12
Counter:     13
Counter:     14
Counter:     15
Counter:     16
Counter:     17
Counter:     18
Counter:     19
Counter:     20
Counter:     21
Counter:     22
Counter:     23
Counter:     24
Counter:     25
Counter:     26
Counter:     27
Counter:     28
Counter:     29
Counter:     30
Counter:     31
Counter:     32
Counter:     33
Counter:     34
Counter:     35
Counter:     36
Counter:     37
Counter:     38
Counter:     39
Counter:     40
Counter:     41
Counter:     42
Counter:     43
Counter:     44
Counter:     45
Counter:     46
Counter:     47
Counter:     48
Counter:     49
Counter:     50
Counter:     51
Counter:     52
Counter:     53
Counter:     54
Counter:     55
Counter:     56
Counter:     57
Counter:     58
Counter:     59
Counter:     60
Counter:     61
Counter:     62
Counter:     63
Counter:     64
Counter:     65
Counter:     66
Counter:     67
Counter:     68
Counter:     69
Counter:     70
Counter:     71
Counter:     72
Counter:     73
Counter:     74
Counter:     75
Counter:     76
Counter:     77
Counter:     78
Counter:     79
Counter:     80
Counter:     81
Counter:     82
Counter:     83
Counter:     84
Counter:     85
Counter:     86
Counter:     87
Counter:     88
Counter:     89
Counter:     90
Counter:     91
Counter:     92
Counter:     93
Counter:     94
Counter:     95
Counter:     96
Counter:     97
Counter:     98
Counter:     99
Counter:     100
Counter:     101
Counter:     102

When you say that my version of the script "critically fails", what happend exactly? What's the Scite console output?

Are you sure that your computer is stable and clean? You might have a bad RAM chip or something like this.

Edited by Neutro

Share this post


Link to post
Share on other sites

#5 ·  Posted

This is what console gives me:

>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\Rimas\Desktop\test11111111.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     1
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     2
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     3
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     4
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     5
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     6
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     7
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     8
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     9
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     10
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     11
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     12
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     13
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     14
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     15
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     16
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     17
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     18
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     19
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     20
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     21
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     22
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     23
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     24
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     25
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     26
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     27
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     28
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     29
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     30
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     31
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     32
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     33
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     34
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     35
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     36
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     37
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     38
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     39
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     40
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     41
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     42
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
Counter:     43
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1899) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject.document^ ERROR
->20:28:28 AutoIt3.exe ended.rc:1
+>20:28:28 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 91.45

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

And without adding "Try to attach" parameter in _IECreate

 

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Counter:     1
Counter:     2
Counter:     3
Counter:     4
Counter:     5
Counter:     6
Counter:     7
Counter:     8
Counter:     9
Counter:     10
Counter:     11
Counter:     12
Counter:     13
Counter:     14
Counter:     15
Counter:     16
Counter:     17
Counter:     18
Counter:     19
Counter:     20
Counter:     21
Counter:     22
Counter:     23
Counter:     24
Counter:     25
Counter:     26
Counter:     27
Counter:     28
Counter:     29
Counter:     30
Counter:     31
Counter:     32
Counter:     33
Counter:     34
Counter:     35
Counter:     36
Counter:     37
Counter:     38
Counter:     39
Counter:     40
Counter:     41
Counter:     42
Counter:     43
Counter:     44
Counter:     45
Counter:     46
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1899) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject.document^ ERROR
->20:35:11 AutoIt3.exe ended.rc:1

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Also, are you using x64 or x86?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I'm running win10 x64 with autoit x86

So the error comes from IE.au3  line 1899. If you open IE.au3 at this line you'll see that it refers to the function

$TxtField = _IEGetObjById($oIEObject, "lst-ib")

This is the exact command line that is failing:

$oIEObject.document.getElementById(lst-ib)

Maybe because for some reason IE didn't have enough time to load this time?

As it's always crashing at loop 46, try to add

if $i = 42 then msgbox("","crash loop", "press OK to continue")

 just before the function _IEGetObjById is called.

This way you can check that the IE window is working properly. Then press OK and see what happens :)

PS : try to clean IE temporary files, shutdown your computer and try again also :P

Edited by Neutro

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Someone had the same problem than you do some month ago:

It seems like it's from a bug in the current autoIT version!

https://www.autoitscript.com/trac/autoit/ticket/3097

Try to use at the start of your script (you must have the full SciTE4Autoit3 installed for this to work):

#AutoIt3Wrapper_UseX64=Y

Then look in the Scite console that you see "autoit3_x64.exe" instead of "autoit3.exe".

If it still doesn't work uninstall your current autoit and install autoit  3.3.12 instead!

Edited by Neutro

Share this post


Link to post
Share on other sites

#10 ·  Posted

Sorry, I meant running script in x86 environment. You have an option to run script either in x86 or in x64 environment. Now I tried running it in x64 and it passed 46 and 42 marks. I did not wait for the crash. However.... I cannot compile script to x64 because of compatibility reasons. Some functions in my script simply does not work when compiled for x64. In this test code x64 would be ok to use.

And... https://www.autoitscript.com/autoit3/docs/appendix/LimitsDefaults.htm I guess it is possible that script exceeds function call limit as described here..?

34 minutes ago, Neutro said:

So the error comes from IE.au3  line 1899.

And when i replace 

$TxtField = _IEGetObjById($oIEObject, "lst-ib")
    $TxtField.value = "lalala"

    $SearchButton = _IEGetObjByName($oIEObject,"btnK")

With this one 

$SearchButton = _IEGetObjByName($oIEObject,"btnK")

    $TxtField = _IEGetObjById($oIEObject, "lst-ib")
    $TxtField.value = "lalala"

It gives different line for the error. So the problem is not with the specific line and I think it is impossible that every time IE would not have time to load on the same loop instance.

All that msgbox/sleep, etc. bs was the first thing I tried and as you might guessed... it did not helped. And regarding temp files, shutdown... Are you starting to troll? :D 

 

So... Does anyone has any idea how to work around MAXCALLRECURSE or any other limit that might play a role here?

Share this post


Link to post
Share on other sites

#11 ·  Posted

Share this post


Link to post
Share on other sites

#12 ·  Posted

Holy crap, it works now. Thanks for the help, mate, you made my day :)

1 person likes this

Share this post


Link to post
Share on other sites

#13 ·  Posted

Glad i could help :)

You're unlucky you had a problem related to an autoIT bug, which is thanksfully quite rare (it's the second time i see something like this since i joined this forum).

I hope you won't think autoit is bad because of it because really it's the opposite ;)

Share this post


Link to post
Share on other sites

#14 ·  Posted

I also encountered this bug previously using excel list also. In that script, autoit kept losing excel object after looping 216 times. And yes, I remember this number correctly because it frustrated me as hell. I completed what I had to do then just by relaunching the script and continuing from where the script crashed. But for this one it was not an option because it crashes way to early.

And of course I will not think autoit is bad :) it has many great inbuilt functions and even more UDF which simplifies what would otherwise be quite complicated. + the community is great :) it motivates to learn and return the favours by adding something to it. 

1 person likes this

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