How to reset the status of a command on loop?

Hi there,

I’m quite new to this tool so I’m still trying to learn. My question is:

How do you reset the status of a command on loop?

Currently, I have a clickandwait command which will throw an error if the desired button is not present on the page. If an error is thrown (meaning the button is not present) I go to the label SKIP which avoids other unnecessary commands. It looks something like this:

“onError” | “#goto” | “SKIP”
“clickAndWait” | “Button” | “”

The problem I am facing is that when looping through the macro the command is still recognized as being an error despite the button being present on the web page. The button is even clicked during the command but the macro is still sent to the SKIP label as though the error occurred again.

I believe that the command is still being recognized as an error from the previous loop and as a result is sending the macro to the label SKIP despite the button being present, meaning the command should theoretically have no error.

I appreciate any help or advice anyone could provide on this!

Thanks

You need to reset statusok to true at start of loop

    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusOK"
    },

https://ui.vision/rpa/docs#!statusok

Unfortunately this didn’t solve my problem. I’ve updated my macro to include it though:

It seems that at the start of every loop the click command is already highlighted in red as well. Is that normal?

As mentioned before, if the click command has an error once it will continue to act as though it has the same error during the next loop even if it should not.

Any other thoughts?

Your macro code is wrong please fix it

Use correct command for if_v2

   {
      "Command": "if_v2",
      "Target": "${!statusOK} == true",
      "Value": ""
    },

Read here how work if_v2 command

https://ui.vision/rpa/docs/selenium-ide/if

I made the change but it doesn’t seem to affect the issue.

I’m quite certain the issue revolves around the click command.

Probably your macro code has other errors, check it line by line, ui vision works perfectly and statusok I use it without any problem so it’s problem of your macro code written in a suboptimal way.

When I create a macro code I look for the best solution, so I use a few hours to avoid using non-optimal commands and this design phase can last even a few days because the secret of a fast and efficient macro is to have a short code and a few commands, complex and long macro codes are slow and can also give sudden errors , ideally, you use as few lines of code as possible for fast, error-free work.

Usually i use more different xpath finder to find alternative best xpath for compatibility and prevent dinamic element in the page.

If the button the click command is looking for is present the entire macro works perfectly without any errors. If the button is not present but is present on the following loop the error occurs regardless of the button being present and clicked.

I have tried optimizing the macro for a few days but I’m unable to avoid this issue.

The statusOK variable is functioning properly but again, after a loop where the click does not function properly due to a missing button, the click command will set the statusOK to false even when it should be true.

I cannot explain why this is happening. If you can think of alternative ways I could set this up that’d be great although the button I am trying to press is dynamic. Sometimes it is there sometimes it is not. It also changes positions on the web page.

Unfortunately I did not understand the work you have to do and I can not think of an alternative solution if I did not understand well the work you have to do, I can tell you from experience that to do any work there are numerous different methods.

I managed to work around the issue.

In place of the click command I made a verifyElementPresent command and moved the click command into the if statement.

So in other words,

  1. If verifyElementPresent doesn’t throw an error (meaning !statusOK == true)
  2. click the button

Else the command is skipped.

This ensures that the click command should never hit an error for a missing button since verifyElementPresent has already determined the button is there.

Thanks for the help :slight_smile:

1 Like