Skip to content

Commit

Permalink
Use NoSuchElementError when element not found in new Element API. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Apr 19, 2024
1 parent 0b3cfb1 commit fb78d12
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
Expand Up @@ -328,9 +328,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
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 fb78d12

Please sign in to comment.