I'm writing a feature test in Rails using RSpec an Capybara. For some reason it doesn't an element by it's id. I've tried several thing to see why it's not finding the element but nothing helped.
Here is my test
require 'rails_helper'
include Warden::Test::Helpers
feature 'Dipole options checkbox' do
before(:each) do
@user = FactoryGirl.create(:user)
@group = FactoryGirl.create(:group)
@user.groups << @group
@stack = FactoryGirl.create(:stack, user: @user, group: @group)
@param_set = FactoryGirl.create(:param_set, user: @user, group: @group, stack: @stack)
end
scenario "when check #dipole-options should be visible" do
login_as(@user, scope: :user)
visit "/param_sets/#{@param_set.id}/edit#box"
page.find(:path, "//input[@id='param_set_mat_dipoles']")
end
end
I have done some debugging and when I look at the HTML that is returned I can see the id param_set_mat_dipoles is present
(byebug) body.include? "#param_set_mat_dipoles"
true
But when I check with in the rspec console
page.find("#param_set_mat_dipoles")
it cannot find the element.
I've done some research and it is able to find the ID of the parent div but when I check the total number op elements (paragraph/p) in that ID it's not finding the last 2.
Has anybody have this before? Could it be that the element is to deeply nested to Capybara cannot in find it?
PS: This is the xpath that it can reach:
path="/html/body/div/div/div[2]/form/div[2]/div[4]/p[7]"
It would find the xpath that I need:
path="/html/body/div/div/div[2]/form/div[2]/div[4]/p[9]"
page.find("#param_set_mat_dipoles", visible: false)- Tom Lord