Skip to content

Commit a05b758

Browse files
authored
Merge pull request #80 from SeasideSt/adapt-movetoelement-offset
Adapt #moveToElement:offset: on BPActions to changes in computation of an element’s in-view center point in chromedriver
2 parents 97fb86a + 2e2f89d commit a05b758

1 file changed

Lines changed: 11 additions & 35 deletions

File tree

repository/Parasol-Core.package/BPActions.class/instance/moveToElement.offset..st

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,29 @@ moveToElement: webElement offset: offset
1212
is constructed, rather than when the move mouse action is executed; in a complicated
1313
BPCompositeAction, the element's in-view center point may change because of an
1414
earlier action. The script that is used is (based on) the one used in chromedriver
15-
to compute an element's in-view center point [2]. It may not be compatible with the
16-
interpretation of in-view center point in other WebDriver implementations [3].
15+
to compute an element's in-view center point [2].
1716
1817
[1] https://github.com/w3c/webdriver/issues/1171
19-
[2] https://chromium.googlesource.com/chromium/src/+/09b268ecde9156723d5ad561de298789b70dffa8/chrome/test/chromedriver/js/get_element_location.js#11
20-
[3] https://bugs.chromium.org/p/chromedriver/issues/detail?id=3190"
18+
[2] https://chromium.googlesource.com/chromium/src/+/093f9b4be6509dc8df62dbd46b8ecc70f2dcf391/chrome/test/chromedriver/js/get_element_location.js#66"
2119

2220
| translatedOffsetCoordinates translatedOffset |
2321

2422
translatedOffsetCoordinates := driver executeScript: '
2523
return (function(element, originalOffsetX, originalOffsetY) {
24+
function getFirstNonZeroWidthHeightRect(rects) {
25+
for (var i = 0; i < rects.length; i++) {
26+
var rect = rects[i];
27+
if (rect.height > 0 && rect.width > 0)
28+
return rect;
29+
}
30+
return rects[0];
31+
}
2632
var rectangles = element.getClientRects();
27-
var rect = rectangles[0];
33+
var rect = getFirstNonZeroWidthHeightRect(rectangles);
2834
var left = Math.max(0, rect.left);
2935
var right = Math.min(window.innerWidth, rect.right);
3036
var top = Math.max(0, rect.top);
3137
var bottom = Math.min(window.innerHeight, rect.bottom);
32-
while (element.parentElement != null &&
33-
element.parentElement != document.body &&
34-
element.parentElement.getClientRects().length > 0) {
35-
var parentStyle = window.getComputedStyle(element.parentElement);
36-
var overflow = parentStyle.getPropertyValue("overflow");
37-
var overflowX = parentStyle.getPropertyValue("overflow-x");
38-
var overflowY = parentStyle.getPropertyValue("overflow-y");
39-
var parentRect = element.parentElement.getClientRects()[0];
40-
if (parentRect.right > left && parentRect.bottom > top &&
41-
right > parentRect.left && bottom > parentRect.top) {
42-
if (overflow == "auto" || overflow == "scroll" || overflow == "hidden") {
43-
left = Math.max(left, parentRect.left);
44-
right = Math.min(right, parentRect.right);
45-
top = Math.max(top, parentRect.top);
46-
bottom = Math.min(bottom, parentRect.bottom);
47-
} else {
48-
if (overflowX == "auto" || overflowX == "scroll" ||
49-
overflowX == "hidden") {
50-
left = Math.max(left, parentRect.left);
51-
right = Math.min(right, parentRect.right);
52-
}
53-
if (overflowY == "auto" || overflowY == "scroll" ||
54-
overflowY == "hidden") {
55-
top = Math.max(top, parentRect.top);
56-
bottom = Math.min(bottom, parentRect.bottom);
57-
}
58-
}
59-
}
60-
element = element.parentElement;
61-
}
6238
var x = 0.5 * (left + right);
6339
var y = 0.5 * (top + bottom);
6440
return [ (Math.floor(rect.left) + originalOffsetX) - Math.floor(x), (Math.floor(rect.top) + originalOffsetY) - Math.floor(y) ];

0 commit comments

Comments
 (0)