diff --git a/lib/api/web-element/commands/isPresent.js b/lib/api/web-element/commands/isPresent.js index 55ee16d66..3a588ee63 100644 --- a/lib/api/web-element/commands/isPresent.js +++ b/lib/api/web-element/commands/isPresent.js @@ -2,6 +2,7 @@ * Checks if an element is present in the DOM. * * This command is useful for verifying the presence of elements that may not be visible or interactable. + * * For more information on working with DOM elements in Nightwatch, refer to the Finding Elements guide page. * * @example @@ -18,7 +19,7 @@ * }); * }); * - * @since 3.5.0 + * @since 3.7.1 * @method isPresent * @memberof ScopedWebElement * @instance diff --git a/lib/api/web-element/scoped-element.js b/lib/api/web-element/scoped-element.js index d801763fc..35209164a 100644 --- a/lib/api/web-element/scoped-element.js +++ b/lib/api/web-element/scoped-element.js @@ -161,7 +161,7 @@ class ScopedWebElement { return webElements[index]; } - async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors}) { + async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure}) { const createAction = () => async ({args}) => { if ((args[0] instanceof Promise) && !args[0]['@nightwatch_element']) { args[0] = await args[0]; @@ -169,10 +169,6 @@ class ScopedWebElement { const parentElement = args[0]; - if (suppressNotFoundErrors) { - this._suppressNotFoundErrors = true; - } - try { if (condition.usingRecursion) { return await this.findElementUsingRecursion({parentElement, recursiveElement: condition, timeout, retryInterval}); @@ -180,7 +176,7 @@ class ScopedWebElement { return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval}); } catch (error) { - if (this._suppressNotFoundErrors) { + if (this.suppressNotFoundErrors) { return null; } @@ -249,8 +245,12 @@ class ScopedWebElement { return resolve(condition); } + if (suppressNotFoundErrors) { + this._suppressNotFoundErrors = true; + } + const webElement = await this.findElementAction({ - parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors + parentElement, condition, index, timeout, retryInterval, abortOnFailure }); resolve(webElement); diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index f0a32136b..b492f1f23 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -585,6 +585,7 @@ module.exports = class MethodMappings { }, async isElementPresent(webElement) { + // webElement would be a Promise in case of new Element API. const element = await webElement; return element instanceof WebElement || element instanceof ShadowRoot;