capybara-webkit icon indicating copy to clipboard operation
capybara-webkit copied to clipboard

Capybara::Webkit::ClickFailed

Open abacha opened this issue 13 years ago • 106 comments

I have this spec:

  context "updating", js: true do
    background do
      create(:visit_report, owner_id: comercial.id)
      visit "/visit_reports/"
    end

    scenario "failure" do
      find(:xpath, '//*[@id="body"]/table/tbody/tr[1]/td[4]/a[2]').click
      within(".clients") { find('.remove').click }
      click_on "Salvar"
      page.should have_content("Clientes não pode ficar vazio")
    end
  end

but when I ran it, it raises an error:

     Failure/Error: find('.remove').click
     TypeError:
       exception class/object expected

I've tried to debug deeply and found this internal message:

"Failed to click element /html/body/div[@id='wrapper']/div[@id='body']/form[@id='edit_visit_report_1']/div[2]/div/div[3]/a at unknown position"

if I change the current_driver to :selenium, it works I'm using capybara-webkit v0.14.1 with capybara v2.0.2

abacha avatar Mar 20 '13 13:03 abacha

Can you paste the full backtrace for the exception? Running with -b will give more detail.

Where did you see that internal message?

jferris avatar Mar 20 '13 14:03 jferris

This can be a duplicate of https://github.com/thoughtbot/capybara-webkit/issues/481 @abacha Could you please check if there are empty elements inside the tag?

@jferris I've reached the internal message using this: https://gist.github.com/abacha/8c7239f04464ff6e8480

backtrace:

Failures:

  1) visit reports updating failure
     Failure/Error: find('.remove').click
     RuntimeError:
       {"json_class"=>"Capybara::Webkit::ClickFailed", "message"=>"Failed to click element /html/body/div[@id='wrapper']/div[@id='body']/form[@id='edit_visit_report_1']/div[2]/div/div[3]/a at unkno
wn position"}
     # ./spec/spec_helper.rb:48:in `rescue in raise_with_helpfulness'
     # ./spec/spec_helper.rb:46:in `raise_with_helpfulness'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/bundler/gems/capybara-webkit-5011593cfc34/lib/capybara/webkit/browser.rb:215:in `check'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/bundler/gems/capybara-webkit-5011593cfc34/lib/capybara/webkit/browser.rb:152:in `command'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/bundler/gems/capybara-webkit-5011593cfc34/lib/capybara/webkit/node.rb:126:in `invoke'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/bundler/gems/capybara-webkit-5011593cfc34/lib/capybara/webkit/node.rb:59:in `click'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/capybara-2.0.2/lib/capybara/node/element.rb:103:in `block in click'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/capybara-2.0.2/lib/capybara/node/base.rb:78:in `synchronize'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/capybara-2.0.2/lib/capybara/node/element.rb:103:in `click'
     # ./spec/features/visit_reports_spec.rb:50:in `block (4 levels) in <top (required)>'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/capybara-2.0.2/lib/capybara/session.rb:214:in `within'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/capybara-2.0.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./spec/features/visit_reports_spec.rb:49:in `block (3 levels) in <top (required)>'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `instance_eval'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `block in run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in `with_around_each_hooks'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:110:in `run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in `block in run_examples'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `map'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `run_examples'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in `run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `map'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block in run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in `report'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run'
     # /home/duke/.rvm/gems/ruby-1.9.3-p392@bigbang/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'

abacha avatar Mar 20 '13 14:03 abacha

@abacha, could you provide the CSS that's applied to that element, or some subset of it? My guess is something is modifying the box such that it has 0 width and height. If there's no other text in the anchor, then there's nothing else we can click on, resulting in a ClickFailed error.

Regarding the unhelpful backtrace, it seems that your JSON library is not respecting the json_class key and therefore not instantiating the exception properly. What version of the JSON gem do you have installed?

mhoran avatar Mar 21 '13 04:03 mhoran

I'm using json 1.7.6 and json_pure 1.7.7

this tag is an icon like these: http://twitter.github.com/bootstrap/base-css.html#icons

abacha avatar Mar 21 '13 04:03 abacha

Thanks, @abacha. Do you happen to be using a font version of the icon (e.g. with a CSS :before pseudo element?) @jnicklas, I believe this may be the same issue you've reported in #481.

mhoran avatar Mar 21 '13 04:03 mhoran

yes! I use fontawesome

abacha avatar Mar 21 '13 04:03 abacha

Yes, I'm using font icons too. Had a really hard time trying to come up with a minimal reproduction of this, but the issue is definitely still there.

jnicklas avatar Mar 21 '13 09:03 jnicklas

Here's a relatively simple repro:

<html>
  <head>
    <style type="text/css">
      i:before { content: 'Hello' }
    </style>
  </head>
  <body>
    <div><a href="#"><i></i></a></div>
  </body>
</html>

In Chrome, document.elementFromPoint returns the wrapper div, which causes our click test to fail. Interestingly, it does not cause a failure with unknown position, but rather the correct point at the center of the rectangle. I'm not sure why both of you are getting unknown position, but the elementFromPoint bug is definitely a problem.

@jonleighton, have you seen anything like this? Any thoughts on how to work around it?

mhoran avatar Mar 21 '13 12:03 mhoran

The key is display: inline-block on the before pseudo element. This causes the anchor rectangle to have 0 width and height in WebKit, though in Chrome it has the proper width and height.

mhoran avatar Mar 21 '13 13:03 mhoran

This is interesting. I haven't seen anything like it, but looks like it might well be a problem in Poltergeist too (I haven't tried yet though).

jonleighton avatar Mar 21 '13 14:03 jonleighton

It looks like this is a WebKit bug. The closest bug I could find was https://bugs.webkit.org/show_bug.cgi?id=104462. It looks like display: inline-block (or block for that matter) doesn't work for pseudo-elements in the WebKit bundled with Qt 4.8 or 5.0. The text added in the content of the pseudo-element is not clickable, unlike in Chrome. I've not been able to reproduce the 0 width and height issue, as now I am getting a proper width and height but document.elementFromPoint does not return the anchor because the <i> is displayed inline.

mhoran avatar Apr 14 '13 23:04 mhoran

Interestingly, Qt 5.0.2 packages WebKit 537.21, and the version of Chrome I'm running was built against version 537.22. So perhaps this is a QtWebKit specific bug.

mhoran avatar Apr 14 '13 23:04 mhoran

Using Capybara 2.1.0 and current capybara-webkit master, I was also unable to click certain elements in a jQueryMobile page. For example, checkboxes [http://jquerymobile.com/demos/1.2.0/docs/forms/checkboxes/] are a problem. They are created with the following HTML:

<div class="ui-checkbox">
  <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom">
  <label for="checkbox-1" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-icon="checkbox-off" data-theme="c" class="ui-btn ui-btn-corner-all ui-btn-icon-left ui-checkbox-off ui-btn-hover-c">
      <span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">I agree</span><span class="ui-icon ui-icon-shadow ui-icon-checkbox-off">&nbsp;</span>
      </span>
    </label>
</div>

Capybara's check() method will find the input element that is visible, but hidden behind the span.ui-icon-checkbox. A click will fail with:

      Failed to click element /html/body[@id='pages']/div[3]/div[3]/form/div/input[@id='checkbox-1'] at position 479, 379 (Capybara::Webkit::ClickFailed)

rbu avatar Apr 26 '13 10:04 rbu

i had the same problem with the button-column of twitter bootstrap, just add some content in empty tag and it works well now

malygin avatar May 06 '13 19:05 malygin

I had the same problem with the button after opening modal window. element.visible? return true, but modal window is not on the screen(i suppose animation in the progress)

simonoff avatar May 18 '13 11:05 simonoff

I experience the same. capybara-webkit v1.0.0

HTML:

<input type="submit" value="Search" class="primary large">

In spec:

click_button "Search"

Are there any work arounds?

greyblake avatar May 22 '13 13:05 greyblake

Same here with a input[type="submit"] which have display: inline-block, among many other styles (I can paste them if it's relevant).

@greyblake : as a workaround, I submit the form with javascript :

page.execute_script %($('form#new_contact').submit())

This is clearly not adequate, but it does the job until this is fixed.

oelmekki avatar May 22 '13 16:05 oelmekki

@oelmekki Thanks!

greyblake avatar May 22 '13 16:05 greyblake