gpt4 book ai didi

robotframework - 等到页面包含元素有效但元素不应该包含

转载 作者:行者123 更新时间:2023-12-04 17:39:26 25 4
gpt4 key购买 nike

尝试验证元素是否包含特定文本,但关键字 Element Should Contain 找不到文本,即使我在 xpath 属性中明确输入它包含文本也是如此。但是关键字 Wait Until Page Contains Element 有效。

运行下面的脚本,得到如下结果

#this was successful
Wait until Page Contains Element xpath://div[@id="header"]//span[contains(text(), "text")]

#this resulted to: should have contained text 'text' but its text was ''
Element Should Contain xpath://div[@id="header"]//span[contains(text(), "text")] text

最佳答案

Element Should ContainWait until Page Contains Element 是有区别的。

第一个将仅检查此时 DOM 是否包含具有该文本子字符串的元素,而最后一个将等待(默认情况下)最多 5 秒让该元素出现在 DOM 中以验证是否它存在。或者,换句话说:第一个检查条件是否正确,另一个监听 DOM 中的变化以检测所需的值。也许您的文本会在加载一段时间后显示?

来自 the documentation :

元素应该包含:

Verifies that element locator contains text expected. ... Use Element Text Should Be if you want to match the exact text, not a substring.

等到页面包含元素:

Waits until element locator appears on current page. Fails if timeout expires before the element appears.

关于robotframework - 等到页面包含元素有效但元素不应该包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55156849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com