Jump to content

Error message but script works


Recommended Posts

Hello,

I use below script to locate an <a> element in an IE page to which a jquery function is attached.  When the element is located, a click on the element executes the jquery function.

...

$tags = $oIE.document.GetElementsByTagName("a")
For $tag in $tags
    $class_value = $tag.className
    If $class_value = "btn-go-to-search-page" Then
      _IEAction ($tag,"click")
      _IELoadWait($oIE,4000)

        Local $linkButton = _IEGetObjById($oIE,"logout")
        _IEAction ($linkButton,"click")
    EndIf
Next
$(".btn-go-to-search-page").click(function () {
    amplify.store("SelectedMenuItemId", null);
    amplify.store("IsCompanySelected", true);
    window.location.href = window.actions.search.url;
});

Strangely the script works, but I get an error in the ouput panel of autoit:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\muehl\Documents\AutoIt\Test.au3"    
"C:\Users\muehl\Documents\AutoIt\Test.au3" (26) : ==> The requested action with this object has failed.:
$class_value = $tag.className
$class_value = $tag^ ERROR
>Exit code: 1    Time: 7.946

The error has something to do with retrieving $class_value.

I would like to know what causes this error ... maybe I am missing something that might get me into problems.

Any ideas or comments?

Thanks, Manu

Link to comment
Share on other sites

@Manu191357
Try to use _IETagNameGetCollection(), so you can see if it is returned correctly a collection.
And, as I always reccomend, use @error debugging, so you can see if there is any error when you call you functions :)

EDIT:

Or, even better, _IELinkGetCollection() :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

3 minutes ago, FrancescoDiMuro said:

@Manu191357
Try to use _IETagNameGetCollection(), so you can see if it is returned correctly a collection.
And, as I always reccomend, use @error debugging, so you can see if there is any error when you call you functions :)

I replaced $tags = $oIE.document.GetElementsByTagName("a") with $tags = _IETagNameGetCollection($oIE, "a") -> script runs successfully, but same error.

How do I use @error debugging?

Link to comment
Share on other sites

13 minutes ago, Manu191357 said:

How do I use @error debugging?

@error is a code that is returned almost from every function in AutoIt.
It indicates that has been an error when you called your function, and, the error code, tells you where the error "appeared".
To debug error codes, just add an If...Else...EndIf statement to your script... Something like this:

Local $intLinksNumber = 0

$tags = _IELinkGetCollection($oIE)
; Start error checking of the calling of the previous function
$intLinksNumber = @extended
If @error Then
    ConsoleWrite("Error while calling the function '_IELinkGetCollection()'. Error: " & @error & @CRLF)
Else
    ConsoleWrite("There have been found '" & $intLinksNumber "' links in the web-page." & @CRLF)
    For $tag in $tags
    $class_value = $tag.className
        If $class_value = "btn-go-to-search-page" Then
        _IEAction ($tag,"click") ; You could do the same here
        _IELoadWait($oIE,4000)   ; You could do the same here

          Local $linkButton = _IEGetObjById($oIE,"logout") ; You could do the same here
          _IEAction ($linkButton,"click") ; You could do the same here
      EndIf
  Next
EndIf

:)

Edited by FrancescoDiMuro
Updated a variable!

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

7 minutes ago, FrancescoDiMuro said:

@error is a code that is returned almost from every function in AutoIt.
It indicates that has been an error when you called your function, and, the error code, tells you where the error "appeared".
To debug error codes, just add an If...Else...EndIf statement to your script... Something like this:

Local $intLinksNumber = 0

$tags = _IELinkGetCollection($oIE)
; Start error checking of the calling of the previous function
intLinksNumber = @extended
If @error Then
    ConsoleWrite("Error while calling the function '_IELinkGetCollection()'. Error: " & @error & @CRLF)
Else
    ConsoleWrite("There have been found '" & intLinksNumber "' links in the web-page." & @CRLF)
    For $tag in $tags
    $class_value = $tag.className
        If $class_value = "btn-go-to-search-page" Then
        _IEAction ($tag,"click") ; You could do the same here
        _IELoadWait($oIE,4000)   ; You could do the same here

          Local $linkButton = _IEGetObjById($oIE,"logout") ; You could do the same here
          _IEAction ($linkButton,"click") ; You could do the same here
      EndIf
  Next
EndIf

:)

I tried this code but get an error ==> Unknown function name.:
intLinksNumber = @extended

Link to comment
Share on other sites

I found the problem.

$tags = _IETagNameGetCollection($oIE,"a")
For $tag in $tags
   $class_value = $tag.className
   If $class_value = "btn-go-to-search-page" Then
        _IEAction ($tag,"click")
   EndIf
Next

_IELoadWait($oIE,4000)
Local $linkButton = _IEGetObjById($oIE,"logout")
_IEAction ($linkButton,"click")

The _IELoadWait($oIE,4000) inside the If-statement of the For-loop causes the error. So I moved the three lines after the For-loop and no errors occur.

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...