diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 3657add..c56dcf1 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -344,10 +344,18 @@ class Cuprite { _isInViewport(node) { let rect = node.getBoundingClientRect(); - return rect.top >= 0 && - rect.left >= 0 && - rect.bottom <= window.innerHeight && - rect.right <= window.innerWidth; + + let inViewport = rect.top >= 0 && + rect.left >= 0 && + rect.bottom <= window.innerHeight && + rect.right <= window.innerWidth; + + if (inViewport) { + let topElement = window.elementFromPoint(x,y); + return topElement == node; + } + + return false; } select(node, value) { diff --git a/spec/features/driver_spec.rb b/spec/features/driver_spec.rb index 1b941ff..da8a054 100644 --- a/spec/features/driver_spec.rb +++ b/spec/features/driver_spec.rb @@ -514,6 +514,12 @@ def create_screenshot(file, *args) expect(@driver.body).to include("x: 100, y: 150") end + it "supports clicking overlayed elements" do + @session.visit("/cuprite/click_overlay") + @session.click_link "hidden link" + expect(@driver.body).to include("hidden-link") + end + it "supports executing multiple lines of javascript" do @driver.execute_script <<-JS var a = 1 diff --git a/spec/support/views/click_overlay.erb b/spec/support/views/click_overlay.erb new file mode 100644 index 0000000..4ec9177 --- /dev/null +++ b/spec/support/views/click_overlay.erb @@ -0,0 +1,47 @@ + + + + + + + +
+
+ hidden link +
+ + +