From f867645b33db2d4ffa3faeebb50ea5150507a2db Mon Sep 17 00:00:00 2001 From: rchettri Date: Wed, 21 Oct 2015 17:59:12 -0400 Subject: [PATCH] Issue 687 - waitForElementVisible fails due to stale element reference error --- lib/api/element-commands/_waitForElement.js | 4 +++ .../src/commands/testWaitForElementVisible.js | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/api/element-commands/_waitForElement.js b/lib/api/element-commands/_waitForElement.js index 9cef0dca03..37d6ccae52 100644 --- a/lib/api/element-commands/_waitForElement.js +++ b/lib/api/element-commands/_waitForElement.js @@ -239,6 +239,10 @@ WaitForElement.prototype.isVisible = function() { return self.elementVisible(result, now); } + if (result.status === -1 && result.errorStatus === 10) { + return self.checkElement(); + } + return self.elementNotVisible(result, now); }); }; diff --git a/tests/src/commands/testWaitForElementVisible.js b/tests/src/commands/testWaitForElementVisible.js index a51feb3bbd..fd9b8ac2aa 100644 --- a/tests/src/commands/testWaitForElementVisible.js +++ b/tests/src/commands/testWaitForElementVisible.js @@ -32,6 +32,40 @@ module.exports = { }); }, + testStaleElementReference : function(test) { + var assertion = []; + this.client.assertion = function(result, actual, expected, msg, abortObFailure) { + Array.prototype.unshift.apply(assertion, arguments); + }; + + MockServer.addMock({ url : '/wd/hub/session/1352110219202/elements', + method:'POST', + response : JSON.stringify({ + status: 0, + state: 'success', + value: [ { ELEMENT: '0' } ] + }) + }, + { + url : '/wd/hub/session/1352110219202/element/0/displayed', + method:'GET', + response : JSON.stringify({ + sessionId: '1352110219202', + state: 'stale element reference', + status:10 + }) + }); + + this.client.api.waitForElementVisible('#weblogin', 110, 50, function callback(result, instance) { + test.equal(assertion[0], false); + test.equal(assertion[1], 'not visible'); + test.equal(assertion[3], 'Timed out while waiting for element <#weblogin> to be visible for 110 milliseconds.'); + test.equal(assertion[4], true); + + test.done(); + }); + }, + 'test not visible with global timeout default': function(test) { var assertion = []; this.client.assertion = function(result, actual, expected, msg, abortObFailure) {