【问题标题】:Robot Framework finds text that does not existRobot Framework 找到不存在的文本
【发布时间】:2017-08-09 17:20:27
【问题描述】:

我正在验证网页上的一些文本。有两条文本应该是互斥的,即在任何时候都应该只有一个文本可见。

元素 xpath=//*[@id="study_info"] 实际上是根据记录检索文本“No records available”或“Showing page x of x”,并且页面上仅显示其中一个文本。如果没有记录,则显示“No record Available”,否则显示“showing Page x of x”

当我尝试在 Robot Framework 中验证这些内容时,它实际上一次找到两个文本,尽管我只能看到一个文本。我不知道这里发生了什么。下面的代码应该会失败,因为文本是互斥的,并且只有一个文本是可见的。但是顺利通过了。

Page Should Contain    No records available
Page Should Contain    Showing page
Page Should Contain Element    xpath=//*[@id="study_info"]

元素的完整代码是

"<div class="dataTables_info" id="study_info" role="status" aria-live="polite">No records available</div>

我需要了解正在发生的事情以及如何解决它。

【问题讨论】:

  • 提示:通过Firefox(或Chrome等效工具)的HTML检查器(开发者工具)检查页面的HTML,不是服务器提供的。 JS 的东西可能会添加不在服务器提供的 HTML 中的元素。

标签: python python-2.7 user-interface robotframework


【解决方案1】:

根据所使用的可视化 (js) 框架,当前不可见的文本很可能在 HTML 中 - div 将其隐藏,放入一堆可能的值等,并且根据需要替换可见元素。

关键字Page Should Contain 遍历整个当前html - 它实际上使用定位器xpath=//*[contains(., %s)],其中%s 是您要查找的字符串,如果有任何(隐藏/覆盖/js 源)元素具有文本,将返回 true。

为了解决您的特殊情况,我建议采用一些不同的方法 - 获取该元素的文本值,并断言它是预期的:

${locator}=    Set Variable    xpath=//*[@id="study_info"]
${current text}=      Get Text   ${locator}
Should Contain        ${current text}    Showing page
Should Not Contain    ${current text}    No records available    # and vice-versa

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 2020-11-24
    • 2021-10-18
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 2021-04-04
    • 2021-03-27
    相关资源
    最近更新 更多