什麼你問能不能用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