diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e74bf49..1339ce6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ node's own frame - `Node#moving?` returned `true` for a node that wasn't moving and `false` for one that was. Its default delay is now 50ms instead of 10ms, which missed a slowly moving node, set it with `FERRUM_NODE_MOVING_CHECK` +- `Node#click` and `#find_position` on a CSS-transformed node whose content quads can't be computed aimed by its + untransformed size and could miss it, now they aim at the center of its bounding rect. An SVG node raised + `JSON::GeneratorError` there [#695] ### Removed - `#evaluate_async`, `#evaluate_func` and `#evaluate_on`, use `#evaluate` and `Node#evaluate`, and diff --git a/lib/ferrum/node.rb b/lib/ferrum/node.rb index 452542c4..aebc8985 100644 --- a/lib/ferrum/node.rb +++ b/lib/ferrum/node.rb @@ -714,9 +714,11 @@ def exists? private def bounding_rect_coordinates - evaluate <<~JS - [this.getBoundingClientRect().left + (this.offsetWidth / 2), - this.getBoundingClientRect().top + (this.offsetHeight / 2)] + evaluate(<<~JS) + function() { + const { left, top, width, height } = this.getBoundingClientRect(); + return [left + (width / 2), top + (height / 2)]; + } JS end diff --git a/spec/node_spec.rb b/spec/node_spec.rb index ef1a6fa4..57f4ed7f 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -192,6 +192,17 @@ expect(browser.url).to eq(base_url("/")) end + + it "clicks the element by its bounding rect when it's transformed" do + browser.go_to("/simple") + link = browser.at_css("#nav") + # Rotated, the link covers the center of its bounding rect, but little else of it. + link.execute("this.style.cssText = 'display: inline-block; width: 200px; height: 20px; transform: rotate(45deg)'") + + link.click + + expect(browser.url).to eq(base_url("/")) + end end it "synchronizes page loads properly" do