diff --git a/lib/api/web-element/isVisible.js b/lib/api/web-element/isVisible.js new file mode 100644 index 0000000000..8c2967bb6a --- /dev/null +++ b/lib/api/web-element/isVisible.js @@ -0,0 +1,29 @@ +/** + * Returns true if the element is visisble. + * + * For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page. + * + * @example + * export default { + * demoTest(browser: NightwatchAPI): void { + * const result = browser.element('#main ul li a.first').isVisible(); + * .assert.valueEquals('custom text'); + * }, + * + * async demoTestAsync(browser: NightwatchAPI): Promise { + * const result = await browser.element('#main ul li a.first').isVisible(); + * console.log('element text:', result); + * } + * } + * + * @since 3.0.0 + * @method isVisible + * @memberof ScopedWebElement + * @instance + * @syntax browser.element(selector).isVisible() + * @see https://www.w3.org/TR/webdriver#dfn-get-element-text + * @returns {ScopedValue} + */ +module.exports.command = function() { + return this.runQueuedCommandScoped('isElementDisplayed'); +}; diff --git a/types/tests/webElement.test-d.ts b/types/tests/webElement.test-d.ts index a85627953f..b759274556 100644 --- a/types/tests/webElement.test-d.ts +++ b/types/tests/webElement.test-d.ts @@ -140,6 +140,7 @@ describe('new element() api', function () { expectType>(elem.getProperty('property-name')); expectType>(elem.getAttribute('attrib-name')); expectType>(elem.getValue()); + expectType>(elem.isVisible()); expectType>(elem.getRect()); expectType>(elem.getSize()); diff --git a/types/web-element.d.ts b/types/web-element.d.ts index 05d68b02f2..79a42d3ac9 100644 --- a/types/web-element.d.ts +++ b/types/web-element.d.ts @@ -188,6 +188,8 @@ export interface ScopedElement extends Element, PromiseLike { rightClick(): Promise; waitUntil(signalOrOptions: WaitUntilActions | WaitUntilOptions, waitOptions?: WaitUntilOptions): Promise; + + isVisible: ElementValue; } type WaitUntilOptions = {