diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 9170892..65ee0ab 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -41,7 +41,7 @@ class Cuprite { parents(node) { let nodes = []; let parent = node.parentNode; - while (parent != document && parent !== null) { + 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 && parent !== null) { - nodes.unshift(parent); - parent = parent.parentNode; - } + let nodes = [node].concat(this.parents(node)); let selectors = nodes.map(node => { let prevSiblings = [];