Click the center of the first non-empty rectangle

Fixes #481.
This commit is contained in:
Matthew Horan 2013-03-03 19:57:42 -05:00
parent cb02ea7752
commit 1de4647fad
2 changed files with 14 additions and 3 deletions

View File

@ -348,6 +348,7 @@ describe Capybara::Session do
<form>
<input type="checkbox" id="bar">
</form>
<div><a href="#"><i></i>Some link</a></div>
<script type="text/javascript">
var targets = document.getElementsByClassName('target');
for (var i = 0; i < targets.length; i++) {
@ -380,6 +381,11 @@ describe Capybara::Session do
subject.find(:css, '#one')['data-click-y'].should == '99'
end
it 'does not raise an error when an anchor contains empty nodes' do
subject.visit('/')
lambda { subject.click_link('Some link') }.should_not raise_error(Capybara::Webkit::ClickFailed)
end
it 'scrolls an element into view when clicked' do
subject.visit('/')
subject.driver.resize_window(200, 200)

View File

@ -146,9 +146,14 @@ Capybara = {
},
clickPosition: function(node) {
var rect = node.getClientRects()[0];
if (rect)
return CapybaraInvocation.clickPosition(node, rect.left, rect.top, rect.width, rect.height);
var rects = node.getClientRects();
var rect;
for (var i = 0; i < rects.length; i++) {
rect = rects[i];
if (rect.width > 0 && rect.height > 0)
return CapybaraInvocation.clickPosition(node, rect.left, rect.top, rect.width, rect.height);
}
},
click: function (index, action) {