Skip to content

Commit 8f0f16b

Browse files
committed
[js] For #4555 protect against the remote end sometimes not returning a list for
findElements.
1 parent 84f64bc commit 8f0f16b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

javascript/node/selenium-webdriver/lib/webdriver.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,15 @@ class WebDriver {
10451045
let cmd = new command.Command(command.Name.FIND_ELEMENTS).
10461046
setParameter('using', locator.using).
10471047
setParameter('value', locator.value);
1048-
let res = this.schedule(cmd, 'WebDriver.findElements(' + locator + ')');
1049-
return res.catch(function(e) {
1050-
if (e instanceof error.NoSuchElementError) {
1051-
return [];
1052-
}
1053-
throw e;
1054-
});
1048+
return this.schedule(cmd, 'WebDriver.findElements(' + locator + ')')
1049+
.then(
1050+
(res) => Array.isArray(res) ? res : [],
1051+
(e) => {
1052+
if (e instanceof error.NoSuchElementError) {
1053+
return [];
1054+
}
1055+
throw e;
1056+
});
10551057
}
10561058
}
10571059

@@ -2076,7 +2078,8 @@ class WebElement {
20762078
command.Name.FIND_CHILD_ELEMENTS).
20772079
setParameter('using', locator.using).
20782080
setParameter('value', locator.value);
2079-
return this.schedule_(cmd, 'WebElement.findElements(' + locator + ')');
2081+
return this.schedule_(cmd, 'WebElement.findElements(' + locator + ')')
2082+
.then(result => Array.isArray(result) ? result : []);
20802083
}
20812084
}
20822085

0 commit comments

Comments
 (0)