英语不是我的第一语言,所以请原谅任何错误。
FCIM:我在Windows 8 x64上的Firefox 53.0.3(64位)上使用iMacros v9.0.3
我正在尝试使用Datasource
循环使用iMacros中的JavaScript代码。
当它只是iim(iMacro)代码时工作正常 它完美地在正确的行号中输入正确的值 但是在我将脚本从iim转换为JavaScript后,它无法正确输入数据。
例如,在我循环的iMacro代码中,它正确地逐行输入数据:
loop1 - kannan1
loop2 - kannan2
loop3 - kannan3 ...
但是在我将其转换为 JavaScript 之后,它总是一遍又一遍地输入相同的数据。
loop1 - kannan1
loop2 - kannan1
loop3 - kannan1 ...
这是我的数据源 demo.csv
这是一个iim代码示例
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
SET !DATASOURCE demo.csv
SET !DATASOURCE_COLUMNS 8
SET !DATASOURCE_LINE {{!LOOP}}
SET !LOOP 1
URL GOTO=http://demo.imacros.net/Automate/AutoDataEntry
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:fname CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:lname CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:address CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:city CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:zip CONTENT={{!COL5}}
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:state CONTENT=%IN
TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:country CONTENT=%73
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:email CONTENT={{!COL8}}
TAG POS=1 TYPE=BUTTON FORM=ID:demo ATTR=TXT:Submit
这是一个Javascript示例代码
var macro;
macro = "CODE:";
for(var X = 1; X <= 10; X++){
macro += "TAB T=1" + "\n";
macro += "TAB CLOSEALLOTHERS" + "\n";
macro += "SET !DATASOURCE demo.csv" + "\n";
macro += "SET !DATASOURCE_COLUMNS 8" + "\n";
macro += "SET !DATASOURCE_LINE {{!LOOP}} " + "\n";
macro += "SET !LOOP 1" + "\n"
macro += "URL GOTO=http://demo.imacros.net/Automate/AutoDataEntry" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:fname CONTENT={{!COL1}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:lname CONTENT={{!COL2}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:address CONTENT={{!COL3}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:city CONTENT={{!COL4}}" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:zip CONTENT={{!COL5}}" + "\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:state CONTENT=%IN" + "\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ID:demo ATTR=ID:country CONTENT=%73" + "\n";
macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=ID:email CONTENT={{!COL8}}" + "\n";
macro += "TAG POS=1 TYPE=BUTTON FORM=ID:demo ATTR=TXT:Submit" + "\n";
iimPlay(macro)
}
iimPlay(macro)
有关如何正确循环的任何想法?并提前告诉我所有的兄弟们:)
答案 0 :(得分:1)
以下是演示伪代码
中的问题的简单示例## Code connection = new DatabaseConnection; print connection.currentrow.firstname; print connection.currentrow.lastname; print connection.currentrow.age; connection.getNextRow(); ## Result Alice Anderson 33
## Code mycode = ""; for ixx in range(0 .. 3): mycode += "connection = new DatabaseConnection;" //<--MISTAKE mycode += "print connection.currentrow.firstname;" mycode += "print connection.currentrow.lastname;" mycode += "print connection.currentrow.age;" mycode += "connection.getNextRow();" myApp.run(mycode);
## Actual Result Alice Anderson 33 Alice Anderson 33 Alice Anderson 33 Alice Anderson 33 ## Desired Result Alice Anderson 33 Bob Banderson 44 Charlie Chanderson 55 Danny Danderson 66 ## BROKEN ;; Actual Result does not match desired result, because ## the DatabaseConnection gets reset every time.
## Fixed code mycode = ""; mycode += "connection = new DatabaseConnection;" //<-- FIXED MISTAKE for ixx in range(0 .. 3): mycode += "print connection.currentrow.firstname;" mycode += "print connection.currentrow.lastname;" mycode += "print connection.currentrow.age;" mycode += "connection.getNextRow();" myApp.run(mycode);
这里似乎重复了同样的错误。这些行不应该在循环内。
SET !DATASOURCE demo.csv SET !DATASOURCE_COLUMNS 8