关于登录验证的脚本
请哪位高手帮我看一下这段代码,哪里写的有问题,在运行的日志里显示“Unexpected Active Window”的警告,我逐行调试,是“ window setcontext, "caption=提示","" ”出的问题,请问该怎样修改呢?'$include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim x as integer
dim strid as string
dim strpsw as string
dim dp as long
'Initially Recorded: 2007-5-1610:56:15
'Script Name: 登录
StartApplication "xx.exe"
dp=SQADatapoolOpen("登录")
for x=1 to 4
Call SQADatapoolFetch(dp)
Call SQADatapoolValue(dp,1,strid)
Call SQADatapoolValue(dp,2,strpsw)
Window SetContext, "Type=Form;Name=LoginFrm", ""
EditBox DblClick, "Type=EditBox;Name=txt_userid;State=Hidden", "Coords=54,9"
InputKeys strid
EditBox DblClick, "Type=EditBox;Name=txt_psw;State=Hidden", "Coords=55,7"
InputKeys strpsw &"{ENTER}"
window setcontext, "caption=提示",""
Result = WindowVP (Exists, "caption=提示", "VP=Window Existence;wait=2,3;expectedresult=fail")
if result=0 then
inputkeys "{enter}"
end if
if result=1 then
Window SetContext, "Type=Form;Name=MDIMain", ""
end if
next
call sqadatapoolclose(dp)
Window CloseWin, "", ""
End Sub
[ 本帖最后由 zhenqi 于 2007-5-16 16:16 编辑 ] 怎么没人回答呀,好失望sdlkfj7 脚本是写的还是录的,有没有改过
看起来是根据这段代码"caption=提示",""找不到窗体,所以window setcontext执行不了 脚本是录制后改过的,警告提示就是“caption=提示”行代码出错 你先获取"caption=提示",""这个窗体的属性(用鼠标直接点一下看看脚本),把出错的那句换成
Window SetContext, "Type=Form;Name=LoginFrm", ""这样的格式 请教:
看你的脚本一定实用了数据池,请教能不能给个创建Datapool的具体实例。
最好是能以你上面的例子为准 早上试了一下,在ViewLog中报“Unexpected Active Window”的警告是由于robot在执行到该语句window setcontext, "caption=提示",""时,有其他的窗口跳出来挡住了“caption=提示”的那个窗口,所以当前活动窗口就不再是“caption=提示”的那个窗口了,在robot7.0中会点掉跳出的窗口以后继续执行后面的语句,我觉得为了防止有不可预见的窗口在语句执行过程中跳出挡住需要设置窗口焦点的活动窗口,可以在window setcontext之前,自己写段脚本去判断当前窗口是不是需要去执行操作的窗口,如果不是,就最小化或者关闭,比方说:
Dim x As Integer
Dim tempCaption As String
x=1
Do
Window SetContext, "CurrentWindow",""
Result = SQAGetPropertyAsString("CurrentWindow","Caption",tempCaption)
If Result = SQASuccess Then
If InStr(tempCaption,"提示") = 0 Then
' Window WMinimize,"",""
Window CloseWin,"",""
InputKeys "%{Tab}"
x=x+1
Else
Exit Do
End If
Else
SQAConsoleWrite "Window caption not found"
InputKeys "%{Tab}"
x=x+1
End If
Loop While x=5
x是循环查找窗口的次数,当然也可以不设置循环次数,那就不断循环直到找到所需要点的那个窗口。
就是比较
[ 本帖最后由 WillTerner 于 2007-8-11 08:07 编辑 ] 在选择窗口之前加入
window resettestcontext, "", ""
将所有窗体至于最前端
之后通过window setcontext指定要选择的对象
尝试一下,应该有用把
页:
[1]