2016-08-11 46 views
2

我想运行一个关键字,如果页面上存在一个元素。机器人框架:如何使等待,直到硒库的关键字返回true或false

我尝试使用Selenium库的Wait Until Page Contains Element关键字,但无论元素是否存在,它都将返回“None”。我尝试设置自定义错误,但不会工作,要么:

${condition} =  Wait Until Page Contains Element ${locator} timeout=5 error=false 
Run Keyword if '${condition}'=='false'  click element ${some_refreshButton_locator} 

关键字时,我提出条件点击元素$ {}定位器将只运行“$ {}条件” ==“无”

我做错了什么,我怎么能做一个硒库等待...关键字返回true或false。

谢谢!

回答

4

等到页面包含元素不会返回任何内容,但会在元素未找到时引发错误。一种解决方法是围绕它运行运行关键字并忽略错误

*** Settings *** 
Library Selenium2Library 

*** Test Cases *** 
Test wait 
    Open Browser  http://www.google.com/ gc 
    ${result} ${condition}= Run Keyword And Ignore Error Wait Until Page Contains Stackoverflow timeout=2 error=false 
    Run Keyword if '${condition}'=='false'  Log clicking 
    Close All Browsers 
+0

佩卡嗨,这伟大工程与不存在的页面上的元素,但我的元素是树状视图中的复选框,它是现有的,但不可见。使用上面的代码片段会抛出“ElementNotVisibleException:Message:Element当前不可见,因此可能不会与之交互”如何捕获它并在抛出时运行关键字? – emi

+0

嗨再次Pekka,我是一个机器人新手,仍在学习。用关键字“等待直到元素可见”对相同的概念进行了尝试,现在它对我来说非常合适。非常感谢! – emi

3

“运行关键字和返回状态”也可以用来获取如下真/假状态:

${condition} =  Run keyword And Return Status Wait Until Page Contains Element ${locator} timeout=5 error=false 
相关问题