Loop different content imacros

时间:2017-08-13 13:43:28

标签: loops imacros

I still new in imacros, how to replace with loop for the list of set content

Here my code:

SET IMAGE1 C:\1.jpg
SET IMAGE2 C:\2.jpg
SET SEL1    612
SET SEL2    271
.
.
.
.
SET SEL50   602

'if possible the image i want to make random for image1 and image2
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_0 CONTENT={{IMAGE1}}
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_1 CONTENT={{IMAGE2}}
'this line of content will replace SEL1 until SEL50
TAG POS=1 TYPE=SELECT FORM=ID:formular ATTR=ID:test CONTENT=%{{SEL1}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:formular ATTR=ID:c_publish

'currently my code will repeat 50 time
 TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_0 CONTENT={{IMAGE1}}
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_1 CONTENT={{IMAGE2}}
TAG POS=1 TYPE=SELECT FORM=ID:formular ATTR=ID:test CONTENT=%{{SEL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:formular ATTR=ID:c_publish
.
.
.

thanks in advance

1 个答案:

答案 0 :(得分:1)

这应该可以完成工作,代码可以循环50次,它使用名为 file_name.csv 的数据源,因此创建它并在第一列中将sel1的值加载到sel50。从我对这个问题的理解,我随机化了image1和image2以在两个图像之间切换。

注意: 不要忘记将第3行中的路径更改为CSV文件的位置。

CODE (根据以下评论的新要求更新)

VERSION BUILD=9030808 RECORDER=FX
SET !ERRORIGNORE YES
SET !DATASOURCE "C:/Users/Testing/Desktop/file_name.csv"
SET !DATASOURCE_COLUMNS 1
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_0 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_1 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_2 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_3 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_4 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_5 CONTENT={{!VAR1}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_6 CONTENT={{!VAR1}}
'this line of content will replace SEL1 until SEL50
TAG POS=1 TYPE=SELECT FORM=ID:formular ATTR=ID:test CONTENT=%{{!COL1}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:formular ATTR=ID:c_publish

<强> CODE:

VERSION BUILD=9030808 RECORDER=FX
SET !ERRORIGNORE YES
SET !DATASOURCE "C:/Users/Testing/Desktop/file_name.csv"
SET !DATASOURCE_COLUMNS 1
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 EVAL("var randomImage=Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_0 CONTENT={{!VAR1}}
SET !VAR2 EVAL("var randomImage= Math.random() >= 0.5 ? 'C:\1.jpg' : 'C:\2.jpg';randomImage;")
TAG POS=1 TYPE=INPUT:FILE FORM=ID:formular ATTR=ID:image_1 CONTENT={{!VAR2}}
'this line of content will replace SEL1 until SEL50
TAG POS=1 TYPE=SELECT FORM=ID:formular ATTR=ID:test CONTENT=%{{!COL1}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:formular ATTR=ID:c_publish

CSV文件(名称:file_name.csv):

202
207
212
217
222
227
232
237
242
247
252
257
262
267
272
277
282