Bug 1239307: Marionette to click on centre first client rect
Updating Marionette to click on the centre of the first client rect instead of
clicking on the centre of the bounding rect. This allows us to click on multiline
links and other items where where are mutliple DOMRects associated with
an element.
--- a/testing/marionette/client/marionette/tests/unit/test_click.py
+++ b/testing/marionette/client/marionette/tests/unit/test_click.py
@@ -27,8 +27,14 @@ class TestClick(MarionetteTestCase):
self.assertEqual(self.marionette.title, "XHTML Test Page")
def test_clicking_an_element_that_is_not_displayed_raises(self):
test_html = self.marionette.absolute_url('hidden.html')
self.marionette.navigate(test_html)
with self.assertRaises(ElementNotVisibleException):
self.marionette.find_element(By.ID, 'child').click()
+
+ def test_clicking_on_a_multiline_link(self):
+ test_html = self.marionette.absolute_url("clicks.html")
+ self.marionette.navigate(test_html)
+ self.marionette.find_element(By.ID, "overflowLink").click()
+ self.wait_for_condition(lambda mn: self.marionette.title == "XHTML Test Page")
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -1465,17 +1465,20 @@ function clickElement(id) {
if (!visible) {
throw new ElementNotVisibleError("Element is not visible");
}
return accessibility.getAccessibleObject(el, true).then(acc => {
checkVisibleAccessibility(acc, el, visible);
if (utils.isElementEnabled(el)) {
checkEnabledAccessibility(acc, el, true);
checkActionableAccessibility(acc, el);
- utils.synthesizeMouseAtCenter(el, {}, el.ownerDocument.defaultView);
+ let rects = el.getClientRects();
+ utils.synthesizeMouseAtPoint(rects[0].left + rects[0].width/2,
+ rects[0].top + rects[0].height/2,
+ {}, el.ownerDocument.defaultView);
} else {
throw new InvalidElementStateError("Element is not Enabled");
}
});
}
/**
* Get a given attribute of an element.