带有内容的Selenium的StaleElementReferenceError已加载内容

Ano*_*oel 7 ruby selenium capybara

我使用selenium驱动程序使用带有Ruby 1.9.3的Capybara,以便从网站上获取信息.点击几页后我访问了我想要的页面并放入:

 all(:css, 'td').each { |td| a_info << td }
 a_info.each {|t| puts t.text }
Run Code Online (Sandbox Code Playgroud)

我等了大约10秒后得到的错误:

[remote server] resource://fxdriver/modules/web_element_cache.js:5628:in `unknown': Element not found in the cache - perhaps the page has changed since it was looked up (Selenium::WebDriver::Error::StaleElementReferenceError)
Run Code Online (Sandbox Code Playgroud)

跟着更多的远程服务器错误.我给了页面10-30秒的睡眠时间,它仍然没有加载,当我打印page.html时,我看到一个javascript脚本,然后我正在尝试从中获取信息的所有td.我知道错误意味着找到的元素不是当前元素,但似乎已经加载了所有元素,所以我不确定它们为什么不再存在.我已经在互联网上搜索了几个小时寻找这个,并希望从可能的解决方案中获得任何帮助,尝试下一步尝试解决这个问题.我可以提供所需的任何额外信息,请告诉我.

Was*_*lho 12

例如,当您创建范围并更改页面时会发生这种情况,但会继续在其中进行断言,如下所示:

within 'selector' do
  expect(page).to have_link 'Link'

  visit 'page'

  expect(page).to have_link 'I do not know this whitin, I am stale.'

  find('I do not know this within, I am stale.').click
end
Run Code Online (Sandbox Code Playgroud)

再次重新打开范围,继续处理旧范围.


Gre*_*reg 5

这是我最不喜欢的错误.我会引用你关于堆栈溢出的这个确切的问题,大约一年前随机"元素不再附加到DOM"StaleElementReferenceException