How to set a loop in iMacros?

2019-07-24 02:51发布

问题:

I have written a macro given below-

VERSION BUILD=844 RECORDER=CR
URL GOTO=https://example.com/form.aspx
WAIT SECONDS= 4

EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type(195)>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS= 15
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type(196)>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS= 15
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type(197)>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS= 15
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type(198)>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS= 15
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type(199)>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS= 15

In each iteration of loop , only the value in 'TBODY>TR:nth-of-type(XXX)' changes. The value of XXX ranges from 1 to 150. How should I convert this into a loop so as to reduce lines of code and improve readibility.

After a bit of research, I found that !LOOP function can be used in iMacros, but I'm unable to get around its syntax. Help me out, please.

回答1:

Try to play this macro repeatedly
(Current: 1 Max: 150, the 'Play Loop' button):

SET url https://example.com/form.aspx
SET url EVAL("({{!LOOP}} == 1) ? '{{url}}' : 'javascript: undefined;';")
URL GOTO={{url}}
SET firstWait EVAL("({{!LOOP}} == 1) ? '4' : '0';")
WAIT SECONDS={{firstWait}}

EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>DIV:nth-of-type(4)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV:nth-of-type(4)>TABLE:nth-of-type(2)>TBODY>TR:nth-of-type({{!LOOP}})>TD:nth-of-type(4)>SPAN:nth-of-type(2)>I" BUTTON=0
WAIT SECONDS=15