Robotframework 我下面的代码还有其他方法吗?
我正在寻找另一种更聪明的方法来实现以下行动Robotframework 我下面的代码还有其他方法吗?,robotframework,Robotframework,我正在寻找另一种更聪明的方法来实现以下行动 ***Keywords*** Insert Values [Documentation] Keyword is used to insert value ${Status1} Run Keyword and Return Status Wait Until Element is Visible ${ONPDonorLocator} 1s ${Status2}
***Keywords***
Insert Values
[Documentation] Keyword is used to insert value
${Status1} Run Keyword and Return Status Wait Until Element is Visible ${ONPDonorLocator} 1s
${Status2} Run Keyword and Return Status Wait Until Element is Visible ${CustomerScoreLocator} 1s
${Status3} Run Keyword and Return Status Wait Until Element is Visible ${ContractDurationLocator} 1s
${Status4} Run Keyword and Return Status Wait Until Element is Visible ${OptionsInstalledLocator} 1s
${Status5} Run Keyword and Return Status Wait Until Element is Visible ${OrderAddsDeletesLocator} 1s
${Status6} Run Keyword and Return Status Wait Until Element is Visible ${SiteCategoryLocator} 1s
Run Keyword If '${Status1}'=='True' Wait and Click ${ONPDonor} ${LocatorWaitTime}
Run Keyword If '${Status2}'=='True' Wait and Click ${CustomerScore} ${LocatorWaitTime}
Run Keyword If '${Status3}'=='True' Wait and Click ${ContractDuration} ${LocatorWaitTime}
Run Keyword If '${Status4}'=='True' Wait and Click ${OptionsInstalled} ${LocatorWaitTime}
Run Keyword If '${Status5}'=='True' Wait and Click ${OrderAddsDeletes} ${LocatorWaitTime}
Run Keyword If '${Status6}'=='True' Wait and Click ${SiteCategory} ${LocatorWaitTime}
预期:
是否可以单击具有“${Status}”==“True”
的定位器,而不是写入Status1
、Status2
、Status3
等?
我不想像上面写的那样写。明天,如果我必须检查几个定位器的状态,那么线路将继续增加
注意:我还在学习,所以欢迎您提出任何建议。是的,使用循环并仅存储可见的定位器;然后在存储的对象上循环,并单击它们:
${visible}= Create List
FOR ${locator} IN ${ONPDonorLocator} ${CustomerScoreLocator} # etc, the others
${Status} Run Keyword and Return Status Wait Until Element is Visible ${locator}
Run Keyword If ${Status} Append To List ${visible} ${locator}
END
FOR ${locator} IN @{visible}
Wait and Click ${locator}
END
当您有更多的元素等待可见性,然后单击时,您只需将它们添加到第一个循环中 Hi@Todor,我运行了上面的代码块,得到了以下错误:从活动工具| FAIL |变量${Locator}中配置Promo::New Promo Configuration未找到
${locator}
是循环中使用的临时变量的名称,它在示例的第2行和第7行声明。我刚刚了解到Python版本>=3.6是新for循环语法的先决条件。我的系统有2.7版,这就是为什么出现上述错误的原因。但无论如何,我的目的已经满足了旧的for循环语法。非常感谢!