diff --git a/javascript/atoms/dom.js b/javascript/atoms/dom.js
index ecc6ac4b85144..30aa362dbe813 100644
--- a/javascript/atoms/dom.js
+++ b/javascript/atoms/dom.js
@@ -1325,7 +1325,9 @@ bot.dom.appendVisibleTextLinesFromNodeInComposedDom_ = function(
} else {
shadowChildren = contentElem.assignedNodes();
}
- goog.array.forEach(shadowChildren, function(node) {
+ const childrenToTraverse =
+ shadowChildren.length > 0 ? shadowChildren : contentElem.childNodes;
+ goog.array.forEach(childrenToTraverse, function (node) {
bot.dom.appendVisibleTextLinesFromNodeInComposedDom_(
node, lines, shown, whitespace, textTransform);
});
diff --git a/javascript/atoms/test/text_shadow_test.html b/javascript/atoms/test/text_shadow_test.html
index fbb292bc6e19a..388ba9306a037 100644
--- a/javascript/atoms/test/text_shadow_test.html
+++ b/javascript/atoms/test/text_shadow_test.html
@@ -71,7 +71,31 @@
let customEl = findElement({ tagName: 'open-shadow-element' });
let text = getText(customEl);
- assertEquals(text, 'full link text');
+ assertEquals('full link text', text);
+ }
+
+ function testTextForSlotValueInShadowDOM() {
+ setCustomElement('