Robot Framework(Python Selenium)中IF分支语句无法执行问题
Robot Framework IF分支未执行问题解决
问题根源是布尔值与字符串的比较不匹配:
Run Keyword And Return Status返回的是原生布尔类型(True/False),不是字符串格式的'True'- 你写的IF条件
${elementvisibity} == 'True',会把布尔值True和字符串'True'做对比,两者不相等,导致条件不成立,分支内代码自然不会执行
修正后的代码(两种写法都有效)
写法1:直接用布尔值作为判断条件
${elementvisibity}= Run Keyword And Return Status Element Should Be Enabled ${loc_ddlRatePlan} IF ${elementvisibity} Wait Until Element Is Enabled ${loc_ddlRatePlan}
写法2:显式和内置布尔变量比较
${elementvisibity}= Run Keyword And Return Status Element Should Be Enabled ${loc_ddlRatePlan} IF ${elementvisibity} == ${True} Wait Until Element Is Enabled ${loc_ddlRatePlan}
补充说明
Robot Framework里,布尔值True可以直接作为IF的判断条件,不用额外做相等比较;如果要显式对比,必须用框架内置的${True}变量,不能用字符串'True'。
内容的提问来源于stack exchange,提问作者vaibhavi reddy
相关产品推荐
相关产品推荐

