我有一个覆盖的形式,我为我们的应用程序创建一个用户。在文本字段中给出详细信息后,我点击保存并尝试捕获在覆盖上出现约一秒钟的成功保存的文本。但是我不能这样做,因为我得到一个错误说"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
在capybara中,我将使用(within)将代码范围限定到Dom中的消息元素,然后使用have_content
within('#Browser div')do
page.should have_content('Saved Successfully')
end
希望这将有助于尝试类似的事情在watir
我从这种情况中理解的是,当您单击保存时,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