Shortcuts for Common Cases
Try steps and Try Next Alternative error handling are very flexible tools. Used in the proper way, they support many different ways to handle errors, and in this topic, we will show a couple of simple and common cases. In fact, these cases are so common that they are also supported by specialized error handling options.
- Skip Following Steps
-
In many cases, a robot must be able to handle optional elements on a web page. That is, if the elements are present, they must be handled (for example, data must be extracted), but if they are absent, the handling of elements can be skipped. Their absence is not an error, but an expected situation. This can be expressed as follows in a robot. Step A tests if the elements are present (by trying to extract something), while steps B and C do further processing that depends on the success of step A.
If step A is not successful (because elements are missing on the web page), its Try Next Alternative () error handling sends notice to the Try step (which is unnamed in this example). This causes the second and empty branch to be executed, after which execution of the whole branch that starts in the Try step is done. Thus steps B and C are not executed if step A is not successful.
This situation happens so often that a specific error handling option, Skip Following Steps, is introduced as a shortcut. It makes it possible to simplify the example as follows.
The error handling for step A is configured as follows. This is the default configuration for all new steps.
Strictly speaking, you need to clear the API Exception and Log as Error check boxes to get exactly the same behavior as shown with the Try step. This is because the default values for these check boxes are different for the two ways to do error handling.
Note that if step B had been similar to step A (that is, if step B had also had Try Next Alternative error handling), this same shortcut could be used.
- Ignore and Continue
-
Sometimes, some action (such as extraction) needs to be done if some condition is met, and otherwise it can be skipped. Subsequent steps do not depend on the result (or a proper default for the result has been set up in advance). This case can be expressed as follows.
If step A is not successful, its Try Next Alternative () error handling causes the second and empty branch from the (unnamed) Try step to be executed. After this, execution continues at step B with the same robot state that was input to step A, thus step A is effectively skipped.
This can also be done without the Try step by using the error handling option Ignore and Continue () on step A.
One interesting possibility is to have the situation logged even though it is otherwise ignored. This can be achieved by configuring error handling on step A as follows.
The same can be done if you prefer to use the method with a Try step.