Skip to content

Commit 35b6e2e

Browse files
samuonglukeis
authored andcommitted
Add optional parameters to control use of Shadow DOM aware atoms.
Signed-off-by: Luke Inman-Semerau <[email protected]>
1 parent 4ededb6 commit 35b6e2e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

javascript/chrome-driver/atoms.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,23 @@ webdriver.chrome.getPageZoom = function(elem) {
287287
* on bot.dom.isShown, but with extra intelligence regarding shadow DOM.
288288
*
289289
* @param {!Element} elem The element to consider.
290+
* @param {boolean=} opt_inComposedDom Whether to check if the element is shown
291+
* within the composed DOM; defaults to false.
290292
* @param {boolean=} opt_ignoreOpacity Whether to ignore the element's opacity
291293
* when determining whether it is shown; defaults to false.
292294
* @return {boolean} Whether or not the element is visible.
293295
*/
294-
webdriver.chrome.isElementDisplayed = function(elem, opt_ignoreOpacity) {
295-
// use bot.dom.isShown to check whether the element is invisible
296-
if (!bot.dom.isShown(elem, opt_ignoreOpacity)) {
297-
return false;
296+
webdriver.chrome.isElementDisplayed = function(elem,
297+
opt_inComposedDom,
298+
opt_ignoreOpacity) {
299+
if (!!opt_inComposedDom) {
300+
if (!bot.dom.isShownInComposedDom(elem, opt_ignoreOpacity)) {
301+
return false;
302+
}
303+
} else {
304+
if (!bot.dom.isShown(elem, opt_ignoreOpacity)) {
305+
return false;
306+
}
298307
}
299308
// if it's not invisible then check if the element is within the shadow DOM
300309
// of an invisible element, using recursive calls to this function
@@ -304,7 +313,8 @@ webdriver.chrome.isElementDisplayed = function(elem, opt_ignoreOpacity) {
304313
topLevelNode = topLevelNode.parentNode;
305314
}
306315
if (topLevelNode instanceof ShadowRoot) {
307-
return webdriver.chrome.isElementDisplayed(topLevelNode.host);
316+
return webdriver.chrome.isElementDisplayed(topLevelNode.host,
317+
opt_inComposedDom);
308318
}
309319
}
310320
// if it's not invisible, or in a shadow DOM, then it's definitely visible

javascript/webdriver/atoms/element.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,16 @@ webdriver.atoms.element.isInHead_ = function(element) {
257257

258258
/**
259259
* @param {!Element} element The element to get the text from.
260+
* @param {boolean=} opt_inComposedDom Whether to get text in the composed DOM;
261+
* defaults to false.
260262
* @return {string} The visible text or an empty string.
261263
*/
262-
webdriver.atoms.element.getText = function(element) {
263-
return bot.dom.getVisibleText(element);
264+
webdriver.atoms.element.getText = function(element, opt_inComposedDom) {
265+
if (!!opt_inComposedDom) {
266+
return bot.dom.getVisibleTextInComposedDom(element);
267+
} else {
268+
return bot.dom.getVisibleText(element);
269+
}
264270
};
265271

266272

0 commit comments

Comments
 (0)