imacros命令.docx
《imacros命令.docx》由会员分享,可在线阅读,更多相关《imacros命令.docx(24页珍藏版)》请在冰豆网上搜索。
imacros命令
Imacros命令使用语法
一、命令参考
1.ADD
功能:
为变量添加一个值
语法:
ADDresult_varadded_value
示例1:
SET !
VAR1100
ADD !
VAR1-20
=>Contentof !
VAR1is80
示例2:
SET !
VAR1Hello
ADD !
VAR1World
ADD !
VAR12010
=>Contentof !
VAR1isHelloWorld2010
示例3:
ADD !
EXTRACT{{!
COL1}}
2.CLICK
语法:
CLICKX=nY=m
示例1:
URLGOTO=
'UseCLICKcommandtoselectApplePiefordessert
CLICKX=316Y=453
3.DISPLAY
语法:
DISPLAYmessage_text
示例:
DISPLAY"Loopis{{!
LOOP}}"
display#HIDEDISPLAY#
Display""
4.EVAL
功能:
重新运算求出参数的内容
示例:
SET!
VAR1EVAL("Math.floor(Math.random()*5+1);")
WAITSECONDS={{!
VAR1}}
5.EVENT
语法:
EVENTTYPE=type[SELECTOR|XPATH]=localizer[BUTTON|POINT|CHAR|KEY]=[button|point|char|key][MODIFIERS=modifiers]
参数:
TYPE
Theeventtypetobefiredbythecommand.Allowedvaluesare:
Mouseevents
∙MOUSEDOWN,
∙MOUSEMOVE,
∙MOUSEUP,
∙CLICK,
∙DBLCLICK
Keyboardevents
∙KEYDOWN
∙KEYUP
∙KEYPRESS
示例:
URLGOTO=
EVENTTYPE=MOUSEDOWNSELECTOR="#preview-svg>svg>svg>svg>foreignObject>DIV"BUTTON=0
EVENTSTYPE=MOUSEMOVESELECTOR="#preview-svg>svg>svg>svg>foreignObject>DIV"POINTS="(131,254),(132,254),(134,254),(136,255),(139,256),(142,256),(147,256),(153,257),(160,257),(169,258),(190,258)"
EVENTTYPE=MOUSEMOVESELECTOR="#containment"POINT="(204,257)"
EVENTTYPE=MOUSEUPPOINT="(386,254)"
6.FILEDELETE
语法:
FILEDELETENAME=file_name
示例:
FILEDELETENAME=c:
\output\mydata.csv
7.FILTER
语法:
FILTERTYPE=IMAGESSTATUS=(ON|OFF)
Parameters
∙TYPE
Specifiesthetypeofelementstofilter.CurrentlyonlyIMAGESissupported
∙STATUS
Specifieswhetherthefilteristurnedonofoff.
8.FRAME
语法:
FRAME(F=n|NAME=id)
示例:
FRAMEF=6
TAGPOS=1TYPE=SPANATTR=TXT:
Selectpath
FRAMENAME=contents
TAGPOS=1TYPE=PFORM=NAME:
f3ATTR=TXT:
*EXTRACT=TXT
9.ONDIALOG
语法:
ONDIALOGPOS=nBUTTON=(OK|YES|NO|CANCEL)[CONTENT=some_content]
示例:
URLGOTO=
ONDIALOGPOS=1BUTTON=OKCONTENT=
TAGPOS=1TYPE=INPUT:
BUTTONFORM=NAME:
NoFormNameATTR=VALUE:
Popup1
ONDIALOGPOS=1BUTTON=OKCONTENT=
TAGPOS=1TYPE=INPUT:
BUTTONFORM=NAME:
NoFormNameATTR=VALUE:
Askmeaquestion
WAITSECONDS=3
TAGPOS=1TYPE=INPUT:
BUTTONFORM=NAME:
NoFormNameATTR=VALUE:
Changebackgroundbacktodefault
10.ONDOWNLOAD
语法:
ONDOWNLOADFOLDER=folder_nameFILE=file_nameWAIT=[YES|NO]CHECKSUM=[MD5|SHA:
hexadecimal_string]
示例1:
ONDOWNLOADFOLDER=*FILE=*
ONDOWNLOADFOLDER=C:
\MyFiles\FILE=myDownload.exe
ONDOWNLOADFOLDER=*FILE=+{{!
NOW:
yymmdd}}
ONDOWNLOADFOLDER=*FILE=*WAIT=YESCHECKSUM=SHA1:
3FD97C2EC475731997F7F28CB5C07F3D1A1E820A
示例2:
‘下载PDF文件
URLGOTO=
ONDOWNLOADFOLDER=*FILE=+_{{!
NOW:
yyyymmdd_hhnnss}}
TAGPOS=1TYPE=AATTR=TXT:
*ViewiMacrosCase*
11.ONERRORDIALOG
语法:
ONERRORDIALOGBUTTON=(YES|NO)CONTINUE=(YES|NO)
12.ONLOGIN
语法:
ONLOGINUSER=usernamePASSWORD=passwordRETRY=[YES|NO]
示例:
ONLOGINUSER=usernamePASSWORD=password
URLGOTO=
13.PAUSE
语法:
PAUSE
如果宏应该等待手动用户输入或进行调试,那么该命令非常有用。
14.PROMPT
语法:
PROMPTprompt_textvariable_name[default_value]
示例:
SET !
ENCRYPTIONNO
PROMPT"Pleaseenteryourpassword:
" !
VAR1
TAGPOS=1TYPE=INPUT:
PASSWORDFORM=NAME:
loginboxATTR=ID:
passCONTENT={{!
VAR1}}
15.PROXY
语法:
PROXYADDRESS=proxy_URL:
port[BYPASS=page_name]
示例:
PROXYADDRESS=192.1.8.1:
8080
PROXYADDRESS=:
8080BYPASS=*imacros*
16.SAVEAS
语法:
SAVEASTYPE=(CPL|MHT|HTM|TXT|EXTRACT|BMP|PNG|JPEG)FOLDER=folder_nameFILE=file_name
示例1:
SAVEASTYPE=MHTFOLDER=*FILE=homepage_current
SAVEASTYPE=BMPFOLDER=C:
\ScreenshotsFILE=+{{!
NOW:
ddmmyyyy}}
SAVEASTYPE=EXTRACTFOLDER="C:
\\MyMacros\\DownloadsFILE=*"
SAVEASTYPE=EXTRACTFOLDER=C:
\MyMacros\DownloadsFILE=*
TAGPOS=1TYPE=H1ATTR=TXT:
*EXTRACT=TXT
SAVEASTYPE=CPLFOLDER=d:
\reportsFILE=report_{{!
EXTRACT}}.htm
示例2:
URLGOTO=
WAITSECONDS=3
URLGOTO=
'Savethepageinallthreedifferentformats
SAVEASTYPE=HTMFOLDER=*FILE=+_{{!
NOW:
yyyymmdd_hhnnss}}
SAVEASTYPE=TXTFOLDER=*FILE=+_{{!
NOW:
yyyymmdd_hhnnss}}
17.SAVETARGETAS
把目标另存
URLGOTO=
'Download1
'Definedownloadfolderandfile
ONDOWNLOADFOLDER=*FILE=+_pdf-file_{{!
NOW:
yyyymmdd_hhnnss}}
'TAGstatement,theCONTENT=EVENT:
SAVETARGETASpartwasaddedmanuallyafterrecording
TAGPOS=1TYPE=AATTR=TXT:
"OpenPDFDocument"CONTENT=EVENT:
SAVETARGETAS
'Download2
ONDOWNLOADFOLDER=*FILE=+_video-file_{{!
NOW:
yyyymmdd_hhnnss}}
TAGPOS=1TYPE=AATTR=TXT:
"PlayVideo"CONTENT=EVENT:
SAVETARGETAS
18.SAVEITEM
语法:
TAGPOS=1TYPE=INPUT:
IMAGEFORM=NAME:
frmImpact2ATTR=ID:
mapimgCONTENT=EVENT:
SAVEITEM
TAGPOS=1TYPE=IMGATTR=HREF:
http:
//*.jpgCONTENT=EVENT:
SAVEITEM
19.SCREENSHOT
语法:
SCREENSHOTTYPE=(PAGE|BROWSER)FOLDER=folder_nameFILE=file_name
示例:
URLGOTO=
SCREENSHOTTYPE=PageFOLDER=*FILE=*
SCREENSHOTTYPE=BrowserFOLDER=*FILE=*
20.SEARCH
语法:
SEARCHSOURCE=(TXT|REGEXP)IGNORE_CASE=YESEXTRACT=$1
示例:
URLGOTO=
'CheckforGAObject
SEARCHSOURCE=TXT:
"'GoogleAnalyticsObject'"
'CheckforGAObject,ignorecase
SEARCHSOURCE=TXT:
"'googleanalyticsobject'"IGNORE_CASE=YES
'Useregularexpressiontoextractdata
SEARCHSOURCE=REGEXP:
"ga\\('create','([^']+)',''\\)"EXTRACT="Trackeris$1"
'Displayextracteddata
PROMPT{{!
EXTRACT}}
21.SET
语法:
SETvarvalue
示例:
SETmyDelay10
WAITSECONDS={{myDelay}}
SET !
VAR1HelloWorld
=>Contentof !
VAR1is"HelloWorld".
22.STOPWATCH
语法:
STOPWATCHLABEL=id
注意:
您需要匹配的一对,因为这个命令返回两个秒表命令之间的差异。
示例:
VERSIONBUILD=8031994
TABT=1
TABCLOSEALLOTHERS
'
'Wecanchangethefolderwheretheperformancelogfileisgoingtobesaved
'bysetting !
FOLDER_STOPWATCH.OtherwiseitissavediniMacros\Downloadsfolder
'SET !
FOLDER_STOPWATCHc:
\Temp
'Note:
UseSET !
FOLDER_STOPWATCHNOifyoudoNOTneedaresponsetimelogfile
'(forexample,ifyouretrievethevalueswiththeScriptingInterfaceviaiimGetStopwatch)
'SET !
FOLDER_STOPWATCHNO
'SET !
FILESTOPWATCHC:
\Temp\demo-stopwatch.csv
'
'Startreponsetimemeasurement
'Measuretotalmacroruntime
STOPWATCHID=Total
'Measureloadtimeforfirstpage
STOPWATCHID=Firstpage
URLGOTO=
STOPWATCHID=Firstpage
TAGPOS=1TYPE=AATTR=HREF:
TAGPOS=1TYPE=INPUT:
TEXTFORM=ACTION:
/Automate/FormSubmitATTR=NAME:
fnameCONTENT=Tom
TAGPOS=1TYPE=INPUT:
TEXTFORM=ACTION:
/Automate/FormSubmitATTR=NAME:
lnameCONTENT=Testerr
'Measureserverreactiononsubmit
STOPWATCHID=SubmitData
TAGPOS=1TYPE=BUTTON:
SUBMITFORM=ID:
demoATTR=TXT:
Submit
STOPWATCHID=SubmitData
STOPWATCHID=Store1
'MeasuretimeforsecureOnlinestoretoopen
'gotostore
URLGOTO=
TAGPOS=1TYPE=AATTR=TXT:
*Buy*
'openstore=>starttimer
TAGPOS=1TYPE=A:
BUTTONATTR=TXT:
BuyNow
STOPWATCHID=Store1
'Measuretimeforsecondpage
STOPWATCHID=Total
WAITSECONDS=2
URLGOTO=
TAGPOS=1TYPE=INPUT:
TEXTFORM=NAME:
form1ATTR=ID:
pathCONTENT="IniMacrosDownloadsfolder"
23.TAB
语法:
TAB(T=n|OPEN|CLOSE|CLOSEALLOTHERS)
关闭是指关闭当前TAB
示例:
'openawebpageinthefirsttab
URLGOTO=
'openanewtab
TABOPEN
'getnewtabtoforeground
TABT=2
'loadanotherpage
URLGOTO=
'closethesecondtab
TABCLOSE
TABT=1
24.TAG
语法:
TAGPOS=nTYPE=type[FORM=form]ATTR=attr[CONTENT=some_content]
Or
TAGXPATH="[xpath_expression]"[CONTENT=some_content]
Or
TAGSELECTOR="[selector_expression]"[CONTENT=some_content]
注意:
POS代表指定HTML元素的出现次数,从网页顶部开始计算
示例1:
Toselectalinkbyitsnameuse
ATTR=TXT:
some_name,
toselectbyitsURLuse
ATTR=HREF:
some_url.
示例2:
!
TIMEOUT_STEP:
标签等待!
TIMEOUT_STEP秒,每秒钟检查一下文本是否在这里。
默认的等待时间是6秒
示例3:
SelectFruits
Apple
Banana
Kiwi
Toselectanentrybyitsnameadda$beforethenamesothatthecommandlookslike
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=$Apple
Toselectanentrybyitsvalueusethepercentsymbol(%)
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=%AP1
Toselectanentrybyitsindexusethe#symbol
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=#2
示例4(多选):
Inmultipleselectionmenusmultipleselectioncanbeachievedbylistingindicesseparatedbyacolon(:
).
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=$Apple:
$*berry*:
$Peach
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=#1:
#3:
#8
示例5:
当您使用$、%和#符号与变量时,符号必须在{{......}}这样,iMacros在解析过程中可以看到变量类型。
这和任何其他脚本语言一样,在使用之前必须声明类型:
ThiswillnotworkiniMacrosForFirefoxorChrome:
'ExampleonhowNOTtoit
SET !
VAR1$*apple*
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT={{!
VAR1}}
Thisworks:
'Correct$,%,#usage
SET !
VAR1*apple*
TAGPOS=1TYPE=SELECTFORM=NAME:
form1ATTR=NAME:
select1CONTENT=${{!
VAR1}}
25.URL
语法:
URLGOTO=some_URL
示例1:
UsingJavascript
URL还可以调用Javascript函数,这些函数要么在这一行中定义,要么嵌入在页面中
URLGOTO=javascript:
alert("TEST");
URLGOTO=
URLGOTO=javascript:
openDemo('shared/flash/imacros1',820,650);
TABT=2
示例2:
Openalocalfile
URLGOTO=file:
///D:
/test/image.png
URLGOTO=file:
///D:
/test/report.html
26.VERSION
语法:
VERSIONBUILD=
指定创建这个宏的iMacros版本。
27.WAIT
语法:
WAITSECONDS=(n|#DOWNLOADCOMPLETE#)
Note:
The#DOWNLOADCOMPLETE#parameterisnotsupported(andnotrequired)iniMacros7(see!
WAITPAGECOMPLETE