【问题标题】:How to wait until an element disappears in Capybara?如何等到元素在 Capybara 中消失?
【发布时间】:2015-02-07 01:18:07
【问题描述】:

注意:当我写完这个问题时,解决方案已经出现了,但也许其他人可能会觉得这很有用,或者可以提供替代方案。

我已阅读以下文章:

但仍然无法为这个特定问题拼凑出答案。

我想等到页面上的某个元素消失后再继续。

此元素与我要单击的另一个元素重叠。当我尝试单击目标元素时,我收到此错误:

Capybara::Poltergeist::MouseEventFailed:
   Firing a click at co-ordinates [1006, 322] failed. Poltergeist detected another element with CSS selector 'html body.widgets div#select2-drop-mask.select2-drop-mask' at this position. It may be overlapping the element you are trying to interact with. If you don't care about overlapping elements, try using node.trigger('click').

我什至尝试使用.trigger('click').trigger(:click),但似乎没有效果。

我尝试过的其他一些东西(“东西”是消失的元素):

@page.wait_until_thing_invisible
 SitePrism::TimeOutWaitingForElementInvisibility:
   execution expired

【问题讨论】:

    标签: ruby capybara site-prism


    【解决方案1】:

    经过更多调查,似乎该元素并没有因为另一个问题而消失。

         Failure/Error: expect(@page.thing.results.map(&:text)).to include a_string_matching 'search_query'
       expected ["Searching…"] to include (a string matching "search_query")
       Diff:
       @@ -1,2 +1,2 @@
       -[(a string matching "search_query")]
       +["Searching…"]
    

    “正在搜索...”显示会出现一瞬间,需要等待才能尝试点击结果。

    所以现在我想等到我没有看到“正在搜索...”,然后继续下一次点击。

    我最终做出了这个 while 声明:

    while search_complete = @page.thing.results.map(&:text).reduce.include?('Searching')
      sleep 1
    end
    

    这似乎要等到“正在搜索...”消失,真正的结果才出现。

    【讨论】:

    • 但如果“搜索”文本持续存在,最后的 while 循环将导致无限循环。
    猜你喜欢
    • 2018-07-31
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2019-05-09
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多