Skip to content

Commit 21848dc

Browse files
committed
Fixed getLocationInView to handle shadowDom.
1 parent e3e3103 commit 21848dc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

javascript/chrome-driver/atoms.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ webdriver.chrome.scrollIntoView_ = function(elem, region, center) {
128128
container.clientHeight);
129129
scrollHelper(container, containerSize, offset, region, center);
130130
container = container.parentNode;
131+
if (SHADOW_DOM_ENABLED && (container instanceof ShadowRoot)) {
132+
container = container.host;
133+
}
131134
}
132135

133136
offset = goog.style.getClientPosition(elem);

javascript/chrome-driver/test/shadow_dom_test.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ <H1>Page for Shadow DOM chromedriver tests</H1>
1414
The page has a shadow root that in turn contains two shadow roots. So we can
1515
check behaviour with both nested roots and younger/older sibling roots. The
1616
various sections are highlighted with colored borders to make it more obvious
17-
where each element comes from.
17+
where each element comes from. Default to pushing the content off the first
18+
screen, to test that scrolling to the elements works.
19+
<div id="padding"></div>
20+
<script>
21+
document.getElementById('padding').style.height = window.innerHeight;
22+
</script>
1823
<div id="outerDiv">
1924
<div id="innerDiv" style="border-style:solid;border-color:yellow">
2025
stuff
@@ -84,12 +89,14 @@ <H4>Younger Child Shadow</H4>
8489
return new goog.math.Coordinate(x, y);
8590
}
8691

87-
8892
function testShadowRootIsElementClickable() {
8993
// check isElementClickable works as expected on elements within a shadow
9094
// DOM
9195
var elemButton = document.querySelector("* /deep/ #olderButton");
9296
var elemText = document.querySelector("* /deep/ #olderTextBox");
97+
98+
// scroll to the element
99+
webdriver.chrome.getLocationInView(elemButton, true);
93100
assertTrue(
94101
"Button #olderButton should be clickable",
95102
webdriver.chrome.isElementClickable(elemButton,

0 commit comments

Comments
 (0)