Verification of presence of one text of 2 texts in the page using selenium2library & Robot Framework

孤街浪徒 提交于 2019-12-22 09:20:07

问题


I want to test if the page contains "TEXT1 or "TEXT2".

Page Should Contain TEXT1 or TEXT2.

Any suggestion how can I do this? Currently I can only check for one text.


回答1:


You can use

Page Should Contain Element

with a locator

xpath=//*[contains(text(),'TEXT1') or contains(text(),'TEXT2')]



回答2:


Thanks Slanec for the info.

I've also found out another way to solve this just using Robot Framework, it goes like this.

@{VAR1} = Run Keyword and Ignore Error Wait Until Page Contains TEXT1 Run Keyword If '@{VAR1}[0]' == 'FAIL' Wait Until Page Contains TEXT2

As the text can be either TEXT1 or TEXT2 depending on the scenario.




回答3:


Use the following three statements:

Pass Execution If '${var1}' == 'TEXT1'

Pass Execution If '${var1}' == 'TEXT2'

Fail




回答4:


${t1 present}=  Run Keyword And Return Status  Page Should Contain  TEXT1
Run Keyword If  not ${t1 present}  Page Should Contain  TEXT2

After line 1 ${t1 present} is True if TEXT1 is present; if so, the check on line 2 will not be ran. If it's False, then the page is checked for TEXT2 - and will fail the case if it's not present.



来源:https://stackoverflow.com/questions/15116652/verification-of-presence-of-one-text-of-2-texts-in-the-page-using-selenium2libra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!