Reputation: 31
I am looking for an alternative and smarter way to achieve the below action
***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}
Expected:
Is it possible to click the locator that has '${Status}'=='True'
instead of writing Status1
, Status2
, Status3
and so on?
I do not want to write the way I have written above. Tomorrow if I have to check status of few more locators then the lines will keep on getting added.
Note: I am still learning, so any suggestions are welcome.
Upvotes: 0
Views: 64
Reputation: 20067
Yes, by using a loop and storing only the locators that are visible; then you loop over the stored ones, and click them:
${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
When you have more elements to wait for visibility and then click, you just add them in the first loop.
Upvotes: 1