robotframework中IF多条件判断

一 run keyword if 多条件判断

同时满足大于等于1小于7,使用and 即可
在这里插入图片描述
执行结果:满足要求!
在这里插入图片描述

#抽奖门槛-奖项等级	还原默认值				
:FOR	${index}	INRANGE	12		
	${n}	Set Variable	${index}+1		
	click element	//tbody/tr[${n}]/td[3]//*[@placeholder='请选择']			
	run keyword if	${index}>=1 and ${index}<7	Set Test Variable	${n}	2
	run keyword if	${index}==7	Set Test Variable	${n}	3
	run keyword if	${index}==8	Set Test Variable	${n}	4
	run keyword if	${index}==9	Set Test Variable	${n}	5
	run keyword if	${index}>=10	Set Test Variable	${n}	6
	${n}	Evaluate	${n}-1		
	sleep	0.3			
	click element	//body/div[last()]//*[text()='${level[${n}]}']	#index=0,一等奖,1~6 二等奖		

在Robot Framework中,“or"对应的符号是”|“,而"and"对应的符号是”&"
使用or 或符号替换and运行实践:

使用&替换and 的结果:在这里插入图片描述
使用or替换and 的结果:
在这里插入图片描述
结论:“&”与“or”执行效果一样,与C知道返回的结果不一致


使用“|”替换“and” 的结果:
在这里插入图片描述
${index}=0,不满足条件结果同“and”;
${index}=1,满足条件结果同“and”;
在这里插入图片描述
${index}=2,不满足条件结果与“and”不同;
在这里插入图片描述
${index}=3,满足条件结果同“and”
在这里插入图片描述
${index}4、6同2, 5 同 3 偶数不满足奇数满足???
结论:“and”不能被符号替换

二 Set Variable if 替换run keyword if

Set Variable if替换run keyword if 实现相同功能:在这里插入图片描述

#抽奖门槛-奖项等级	还原默认值				
:FOR	${index}	INRANGE	12		
	${n}	Evaluate	${index}+1		
	click element	//tbody/tr[${n}]/td[3]//*[@placeholder='请选择']			
	${n}	Set Variable if	${index}>=1 and ${index}<7	2	${n}
	${n}	Set Variable if	${index}==7	3	${n}
	${n}	Set Variable if	${index}==8	4	${n}
	${n}	Set Variable if	${index}==9	5	${n}
	${n}	Set Variable if	${index}>=10	6	${n}
	${n}	Evaluate	${n}-1		
	sleep	0.3			
	click element	//body/div[last()]//*[text()='${level[${n}]}']			

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值