Search code examples
ruby-on-railsrspecwebkitcucumbercapybara

Capybara webkit driver found overlaps element, how can I click one of them?


Capybara webkit driver see my css incorrectly. It sees(displays) my button overlaps another button, while selenium driver got no problem.

Is there anyway I can click on it? may be execute script or something?


Solution

  • With Capybara you can trigger click events instead of directly clicking on an element like so:

    page.find("#some_element").trigger("click")
    

    The problem is this doesn't work in Selenium. So what you can do is conditionally perform a standard capybara click or a trigger("click") based on the current javascript driver, which would look something like:

    if Capybara.javascript_driver == :selenium
      page.find("#some_element").click
    else
      page.find("#some_element").trigger("click")
    end
    

    Obviously this is less than ideal, but it's the best way I've found to deal with situations like these.