From 1345137dc5173e868de4b9da6ed16b7928e4c50e Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Thu, 22 Dec 2016 12:54:45 -0800 Subject: [PATCH] fix(isElementPresent): for un-wrapped `WebElement`s, `browser.isElementPresent` was broken (#3871) Closes #3864 --- lib/browser.ts | 14 ++++++++++---- lib/element.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/browser.ts b/lib/browser.ts index c4c141216..7ff254eb6 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -589,10 +589,16 @@ export class ProtractorBrowser extends Webdriver { * @returns {!webdriver.promise.Promise} A promise that will resolve to whether * the element is present on the page. */ - isElementPresent(locatorOrElement: ProtractorBy|WebElement): wdpromise.Promise { - let element = - ((locatorOrElement as any).isPresent) ? locatorOrElement : this.element(locatorOrElement); - return (element as any).isPresent(); + isElementPresent(locatorOrElement: Locator|WebElement|ElementFinder): wdpromise.Promise { + let element: ElementFinder; + if (locatorOrElement instanceof ElementFinder) { + element = locatorOrElement; + } else if (locatorOrElement instanceof WebElement) { + element = ElementFinder.fromWebElement_(this, locatorOrElement); + } else { + element = this.element(locatorOrElement); + } + return element.isPresent(); } /** diff --git a/lib/element.ts b/lib/element.ts index 8405093af..724c7ac45 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -844,7 +844,7 @@ export class ElementFinder extends WebdriverWebElement { }); } - static fromWebElement_(browser: ProtractorBrowser, webElem: WebElement, locator: Locator): + static fromWebElement_(browser: ProtractorBrowser, webElem: WebElement, locator?: Locator): ElementFinder { let getWebElements = () => { return wdpromise.fulfilled([webElem]);