LoginSignup
4
2

More than 5 years have passed since last update.

PhantomJS 2.1.1にアップデート後、attach_fileでCapybara::Poltergeist::ObsoleteNodeエラーが出る場合

Last updated at Posted at 2016-09-13

遭遇した問題

PhantomJS 1.9系からPhantomJS 2.1.1にアップデートした後、既存のテストコードを実行すると次のようなエラーが出た。

Capybara::Poltergeist::ObsoleteNode:
 The element you are trying to interact with is either not part of the DOM, or is not currently visible on the page (perhaps display: none is set). It's possible the element has been replaced by another element and you meant to interact with the new element. If so you need to do a new 'find' in order to get a reference to the new element.
# ./spec/features/posts_spec.rb:15:in `block (2 levels) in <top (required)>'
# ./spec/rails_helper.rb:67:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# Capybara::Poltergeist::BrowserError:
#   There was an error inside the PhantomJS portion of Poltergeist. If this is the error returned, and not the cause of a more detailed error response, this is probably a bug, so please report it. 
#   
#   Poltergeist.ObsoleteNode: 
#   ./spec/features/posts_spec.rb:15:in `block (2 levels) in <top (required)>'

エラーが発生する箇所

問題が発生するのはattach_fileメソッドを使っている箇所。

file_path = "#{Rails.root}/spec/fixtures/images/sample.png"
attach_file '添付画像', file_path

なおかつ、View側ではjquery-fileuploadプラグインを使ってファイルをAjaxでアップロードしていた。

原因と解決策

CapybaraとPoltergeistのバージョンが古かった。最新版をインストールしたら直りました。。

Before/After

  • Capybara 2.5.0 => 2.8.1
  • Poltergeist 1.8.1 => 1.10.0

教訓

PhantomJSのバージョンを上げたら、CapybaraとPhantomJSも最新版にアップデートしましょう!!

関連Issue

Getting `Capybara::Poltergeist::ObsoleteNode` using Phantomjs 2.1 · Issue #725 · teampoltergeist/poltergeist

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2