【问题标题】:Verify for the text to be present in an overlay using watir-webdriver使用 watir-webdriver 验证文本是否存在于叠加层中
【发布时间】:2014-08-13 00:19:57
【问题描述】:

我有一个覆盖表单,我在其中为我们的应用程序创建了一个用户。在文本字段中提供详细信息后,我单击保存并尝试捕获已成功保存的文本,该文本在叠加层上显示了大约一秒钟。但我无法这样做,因为我收到一条错误消息 "Element is no longer attached to the DOM (Selenium::WebDriver::Error::StaleElementReferenceError)"

我使用了以下代码:

if($browser.div(:class=>"validation-summary-valid").exists?)
   message=$browser.div(:class=>"validation-summary-valid").li.text
   if(message=="Saved Sucessfully")
     puts("Save action complete")
    else
     fail("fail")       
   end 
end

【问题讨论】:

  • 尝试验证暂时的东西可能不是一个好主意。根据时间的不同,您最终可能会出现随机故障。我建议你测试一些静态的东西。
  • 好的,贾斯汀,感谢您的回复,

标签: ruby cucumber watir


【解决方案1】:

在 capybara 中,我将使用 (within) 将代码范围限定为 Dom 中的消息元素,然后使用 have_content

within('#Browser div')do 
page.should have_content('Saved Successfully') 
end

希望这将有助于在 watir 中尝试类似的东西

【讨论】:

    【解决方案2】:

    我从这种情况的理解是,当你点击保存的那一刻,UI 上会出现一条临时消息,需要进行检查。

    在这种情况下,下面的方法应该可以正常工作,

    # the browser waits for 20 s until the element is present(exists+visible) on the UI
    $browser.div(:class=>"validation-summary-valid").wait_until_present(20).li.text
    

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多