Poltergeist detected another element with CSS selector

Posted . Visible to the public.

If you get errors in CI like Poltergeist detected another element with CSS selector but you're not getting them in development/testing then it could be to do with the fact that you have a responsive layout and when the screen is collapsed the elements are obscured so Capybara cannot determine which one is correct.

This can be solved by setting the window size for Poltergeist to an appropriate value in the config for Capybara like so:

require 'capybara/poltergeist'

Capybara.register_driver :poltergeist do |app|
  options = { :js_errors => false, :timeout => 30, :window_size => [1920, 1080] }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.configure do |config|
  config.run_server = false
  config.default_driver = :poltergeist
  config.javascript_driver = :poltergeist
end
Andy Henson
Last edit
Andy Henson
Posted by Andy Henson to Foxsoft (2016-02-25 18:44)