diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index 5cba89ad5..73b812e74 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -375,11 +375,12 @@ export class TestingBehatDomUtilsService { return element; } - if (element === container || !element.parentElement) { + const parent = this.getParentElement(element); + if (element === container || !parent) { return null; } - return this.getClosestMatching(element.parentElement, selector, container); + return this.getClosestMatching(parent, selector, container); } /**