ruby-on-railscapybaracapybara-webkit

rspec have_selector with div and i elements are not working


I have upgraded my capybara from 2.x to capybara 3.13.x noticed that

  expect(html).to have_selector("div", "result-item-area")

starts failing tried various fix but nothing helped me and unable to figure out the reason for the below failure

Unused parameters passed to Capybara::Queries::SelectorQuery : ["result-item-area"]

Solution

  • If you want to check wheather div with class result-item-area exists, you should use following code:

    expect(html).to have_selector('div', class: 'result-item-area')
    

    Or

    expect(html).to have_selector('div.result-item-area')
    

    Alternatively for id:

    expect(html).to have_selector('div', id: 'result-item-area')
    

    Or

    expect(html).to have_selector('div#result-item-area')