Skip to content

Commit

Permalink
Use NoSuchElementError when element not found in new Element API. (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored and dikwickley committed Oct 15, 2024
1 parent 387d5be commit 9f765ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 8 additions & 3 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,14 @@ class ScopedWebElement {
}

function createNarrowedError({error, condition, timeout}) {
return error.name === 'TimeoutError'
? new Error(`Timed out while waiting for element "${condition}" to be present for ${timeout} milliseconds.`)
: error;
if (error.name === 'TimeoutError') {
const err = new Error(`Timed out while waiting for element "${condition}" to be present for ${timeout} milliseconds.`);
err.name = 'NoSuchElementError';

return err;
}

return error;
}

module.exports = ScopedWebElement;
11 changes: 4 additions & 7 deletions lib/transport/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,13 @@ module.exports = {
if (err && (err.name in SeleniumNightwatchErrorCodeMap)) {
const statusCode = SeleniumNightwatchErrorCodeMap[err.name];

const error = {
...err,
id: statusCode
};

for (const [key, value] of Object.entries(Errors[statusCode])) {
error[key] ||= value;
err[key] ||= value;
}

return error;
err.id = statusCode;

return err;
} else if (err && err.name && (err.stack || err.stackTrace)){
return err;
}
Expand Down

0 comments on commit 9f765ac

Please sign in to comment.