Skip to content
This repository has been archived by the owner on May 22, 2018. It is now read-only.

Commit

Permalink
stop gap to help with elementFromPoint not being completely reliable
Browse files Browse the repository at this point in the history
adding test where child element gets parent element chosen instead by elementFromPoint
  • Loading branch information
lukeis committed Feb 4, 2016
1 parent dba2671 commit 84aaf1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common/src/web/click_tests/html5_submit_buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<label for="name">Enter your name: </label><input type="text" name="name" id="name"/>
<button id="internal_explicit_submit" type="submit">Explicit Submit</button>
<button id="internal_implicit_submit">Implicit Submit</button>
<button type="submit"><span id="internal_span_submit">Spanned Submit</span></button>
</form>
<button id="external_explicit_submit" type="submit" form="form1">Explicit Submit</button>
<button id="external_implicit_submit" form="form1">Implicit Submit</button>
</body>
</html>
</html>
7 changes: 7 additions & 0 deletions java/client/test/org/openqa/selenium/FormHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ public void testCanClickOnASubmitButton() {
checkSubmitButton("internal_explicit_submit");
}


@Ignore(value = {SAFARI}, reason = "untested")
@Test
public void testCanClickOnASubmitButtonNestedSpan() {
checkSubmitButton("internal_span_submit");
}

@Ignore(value = {SAFARI}, reason = "untested")
@Test
public void testCanClickOnAnImplicitSubmitButton() {
Expand Down
13 changes: 13 additions & 0 deletions javascript/firefox-driver/js/syntheticMouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ SyntheticMouse.prototype.isElementClickable = function(element) {
parentElemIter = parentElemIter.parentNode;
}

// elementFromPoint is not without fault, for example:
// <button><span></button> and span.click() results in
// elementAtPoint being the button rather than the span.
// catch these potential edge cases by checking if the
// target element is a direct descendent of the elementAtPoint
parentElemIter = element.parentNode;
while (parentElemIter) {
if (parentElemIter == elementAtPoint) {
return;
}
parentElemIter = parentElemIter.parentNode;
}

var elementAtPointHTML =
elementAtPoint.outerHTML.replace(elementAtPoint.innerHTML, '');

Expand Down
12 changes: 12 additions & 0 deletions javascript/firefox-driver/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,18 @@ Utils.getClickablePoint = function(element) {
}
parentElemIter = parentElemIter.parentNode;
}

// elementFromPoint does not appear to be reliable. This will catch
// other cases where the parent element is found instead.
// ex. <button><span/><button>, click on span, but elementFromPoint
// returned the button element.
parentElemIter = element.parentNode;
while (parentElemIter) {
if (parentElemIter == elementAtPoint) {
return true;
}
parentElemIter = parentElemIter.parentNode;
}
};

var rectPointRelativeToView = function(x, y, r) {
Expand Down

0 comments on commit 84aaf1d

Please sign in to comment.