From b9a67c0469535dd7972ac0d19061a0ae48b83633 Mon Sep 17 00:00:00 2001 From: Ed Lebert Date: Sat, 20 Apr 2019 13:13:17 -0500 Subject: [PATCH] Safely evaluate parents and path for orphan nodes. It's possible for Cuprite to evaluate the parents or the path for a node that no longer belongs to the document. --- lib/capybara/cuprite/browser/javascripts/index.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/capybara/cuprite/browser/javascripts/index.js b/lib/capybara/cuprite/browser/javascripts/index.js index dee26b7..e9c99f5 100644 --- a/lib/capybara/cuprite/browser/javascripts/index.js +++ b/lib/capybara/cuprite/browser/javascripts/index.js @@ -41,7 +41,7 @@ class Cuprite { parents(node) { let nodes = []; let parent = node.parentNode; - while (parent != document) { + while (parent && parent !== document) { nodes.push(parent); parent = parent.parentNode; } @@ -95,12 +95,7 @@ class Cuprite { } path(node) { - let nodes = [node]; - let parent = node.parentNode; - while (parent !== document) { - nodes.unshift(parent); - parent = parent.parentNode; - } + let nodes = [node].concat(this.parents(node)); let selectors = nodes.map(node => { let prevSiblings = [];