How Can We Help?
< All Topics

How can I have a macro continue even if the web page does not load?

Use the Get Pixel Color command to do this.

To use the Get Pixel Color command you will need to determine somewhere on the screen that changes colors when the page has finished loading, such as the Done message. Then you can set up a loop like the following to repeat until the color has changed.

Use the Mouse Locator to find the screen coordinates and the color value to use in the If Variable %N[2]% = command. Below is a sample of how this would look. You will need to modify the screen coordinates and color value (N[2]) for your own situation.

Variable Set Integer %N[1]% to 0
Repeat Until %N[1]% = 1
Get Pixel: Screen Coords: 100,100 into %N[2]%
If Variable %N[2]% = 186023
Variable Set Integer %N[1]% to 1
End If
Repeat End

In the above example the macro will loop indefinitely until the condition is met. Here is how you would set the macro to repeat for a fixed amount of time and if the page has not loaded, continue with the rest of the macro.

We need to insert a second If statement within the Repeat loop. This loop will be the timer. In this example we have inserted a .5 (half) second delay.

If Variable N[4] reaches twenty (or in essence repeats 20 times), then the macro will exit from the Repeat loop and continue with the rest of the macro.

Since we set the delay to a half second, 20 times through the loop will take approximately 10 seconds. If the Pixel color has not been found in 10 seconds (in other words, the page has not loaded), the macro will exit the loop and continue with any commands after the Repeat End command.

Variable Set Integer %N[4]% to 0
Repeat Until %N[1]% = 1
Get Pixel: Screen Coords: 46,64 into %N[2]%
Variable Modify Integer: %N[4]% = %N[4]% + 1
Delay 0.5 Seconds
If Variable %N[2]% = 11711154
Variable Set Integer %N[1]% to 1
End If
If Variable %N[4]% = 20
Repeat Exit
End If
Repeat End

To increase the amount of time to wait, increase the Delay time or increase the If Variable %N4% = 20 to a greater number.

This technique may be applied to other Wait situations as well, besides just waiting for a web page to load.

– Applies to: Macro Express  and Macro Express Pro