什么你问能不能用Run Keyword And Return Status
呼叫组合来完成。
${el1 present}= Run Keyword And Return Status Page Should Contains Element //some xpath1
${el2 present}= Run Keyword And Return Status Page Should Contains Element //some xpath2
${el3 present}= Run Keyword And Return Status Page Should Contains Element //some xpath3
${el4 present}= Run Keyword And Return Status Page Should Contains Element //some xpath4
Run Keyword If not ${el1 present} or not ${el2 present} or not ${el3 present} or not ${el4 present} Fail None of the elements is present on the page
虽然这种方法很简单,它是次优的 - 它会检查每一个元素,即使第一个可能存在,并且没有需要检查的第二,第三和第四位。这(很expresive)版本将做到这一点:
${some element present}= Run Keyword And Return Status Page Should Contains Element //some xpath1
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status Page Should Contains Element //some xpath2 ELSE Set Variable ${some element present}
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status Page Should Contains Element //some xpath3 ELSE Set Variable ${some element present}
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status Page Should Contains Element //some xpath4 ELSE Set Variable ${some element present}
Run Keyword If not ${some element present} Fail None of the elements is present on the page
它使用Run Keyword If
返回称为关键字的值的事实。总之,当应该检查所有条件(Page Should Contain Element
)(在末端具有相应的逻辑条件 - 与and
连接,而不是or
,如本示例中)时,第一种方法更好地使用。
第二 - 只有一个就足够了,其余的不应该检查,如果发现一个是真的。
非常感谢你@ ombre42您的帮助:) 我发现我的问题替代的解决方案,从你的回答再次 谢谢:) – Umesh
@Umesh这本来是巨大的,如果你张贴在这里您的解决方案,因为我期待替代xpath以及=) – Shnigi
@Shnigi我想检查用户状态,无论是在线,离线,离开,忙碌。但稍后,我使用“获取匹配Xpath计数”显示了用户数量以及状态,如下所示: $ {USERS_ONLINE}获取匹配Xpath计数// div [@ class ='participants-list'] // span [@ [= class ='status available'] Log $ {USERS_ONLINE} user available(s)available $ {USERS_OFFLINE}获得匹配Xpath计数// div [@ class ='participants-list'] // span [@ class ='status unavailable '] 登录$ {USERS_OFFLINE}个用户离线 – Umesh