【问题标题】:Robot Framework - Wait until a form textfield contains textRobot Framework - 等到表单文本字段包含文本
【发布时间】:2018-05-15 09:48:53
【问题描述】:

对于我的测试,我需要等到表单文本字段填满文本,然后我想检查该文本。这是一个地址表格,它会根据邮政编码自动填写街道和城市。

使用“等到元素包含”对我不起作用,我想避免使用睡眠,然后使用“文本字段应包含”,因为时间可变。

谢谢!

【问题讨论】:

  • 您能否详细说明“不起作用”的含义。你描述的是Wait until Element Contains的预期功能。
  • 关键字看不到文字出现,一直等到超时。如果我用相同的定位器检查它的“文本字段应该包含”,它会找到文本。
  • 我有类似的问题。我发现Wait for condition 是一种检查表单输入是否已更改的简单方法。

标签: robotframework textfield wait


【解决方案1】:

在@Todor 的帮助下,我最终使用了它:

Wait Until Keyword Succeeds    1min    1s    Textfield Should Contain    Fieldname    Value

【讨论】:

    【解决方案2】:

    Wait Until Element Contains 不适合您,因为它“等待”元素的文本具有所需的值 - 即 in the documentation

    同时,Textfield Should Contain 作用于<input> html 元素,并检查它们的value 属性(这是存储用户设置的文本的内容)。因为它确实对您有用,所以您的目标元素是 <input> 一个,对吧?

    为了得到value,你应该使用关键字Get Element Attribute来获取属性的值;要等到它更新,你可以把它包裹在Wait Until Keyword Succeeds - 这是后者的documentation

    一个粗略的样本:

    *** Test Cases ***
    Check the value is correct
        Wait Until Keyword Succeeds    retry=10s    retry_interval=200ms    The value of the input should be    expected text
        # will check the value of the input every 200ms, and continue if it matches "expected text"
        # if it does not matches in 10 seconds, the keyword and the case will be failed.
    
    *** Keywords ***
    The value of the input should be
        [Arguments]    ${expected}
        ${actual value}=    Get Element Attribute    locator_for_the_element    value
        Should Be Equal As Strings    ${actual value}    ${expected}
    

    【讨论】:

    • 谢谢!使用您的解决方案,我制作了自己的解决方案,请参见下文
    【解决方案3】:

    您可以使用元素应包含关键字 Element Should Contain xpath=//div[@class="clr"] sampleText

    【讨论】:

      猜你喜欢
      • 2018-02-06
      • 2017-04-02
      • 2021-03-31
      • 2021-06-11
      • 1970-01-01
      • 2018-12-28
      • 1970-01-01
      • 2020-12-31
      • 2017-03-25
      相关资源
      最近更新 更多