【问题标题】:Robot Framework: How to make Wait until keyword from selenium library return true or false机器人框架:如何等待硒库中的关键字返回真或假
【发布时间】:2016-12-18 08:30:48
【问题描述】:

如果页面上存在元素,我想运行关键字。

我尝试使用 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}

关键字点击元素 ${locator} 只会在我设置条件 '${condition}'=='None' 时运行

我是不是做错了什么?如何让 Selenium 库等到...关键字返回 true 或 false。

谢谢!

【问题讨论】:

    标签: selenium wait robotframework


    【解决方案1】:

    等到页面包含元素 不会返回任何内容,但如果找不到元素则会引发错误。一种解决方法是将 Run Keyword And Ignore Error 包裹起来。

    *** 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
    

    【讨论】:

    • 嗨 Pekka,这对页面上不存在的元素非常有效,但我的元素是树视图中存在但不可见的复选框。使用上面的代码 sn-p 会抛出“ElementNotVisibleException:消息:元素当前不可见,因此可能无法与之交互”如何捕获它并在抛出关键字时运行它?
    • 您好 Pekka,我是 Robot 的新手,还在学习。使用关键字“等到元素可见”尝试了相同的概念,现在它对我来说效果很好。非常感谢!
    【解决方案2】:

    “运行关键字并返回状态”也可用于获取真/假状态,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2014-03-07
      • 2013-11-08
      • 2018-03-08
      • 2018-12-21
      • 2016-01-03
      • 2018-06-27
      • 2019-07-04
      • 2017-09-18
      • 2017-08-09
      相关资源
      最近更新 更多