You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stale element Exception thrown in "expect" and "waitForElementNotPresent" when target is a (sub-)section or element of a (sub-)section, but test still passes.
#1615
Closed
newhouse opened this issue
Oct 16, 2017
· 1 comment
Hi there,
My issue is quite similar to #687 and #642 . However, I'm unable to rectify it. It only happens "sometimes" so it's clearly some sort of race condition as to whether the bug occurs, but I believe this is a bug and is not the expected behavior. Expected behavior would be for nightwatch to not care about stale elements Exceptions, and only determine if the test/expectation is met or not within the timeout period. This is the assumed behavior in the other tickets as well.
I think the significant difference between my scenario and the scenarios accounted for and/or fixed in the other issues may be that my scenario is targeting section elements and/or elements underneath sections. Let me explain with some code:
// myPage.js
module.exports = {
...
// This is not exactly what I have but I believe it's representative enough
sections: {
a: {
selector: 'a',
sections: {
b: {
selector: 'b',
elements: {
targetElement: {
selector: 'div.target'
}
}
}
}
}
}
};
// myTest.js
...
// This will sometimes hang for 60 seconds or so and produce Selenium error, but then ultimately passes and moves on.
myPage.section.a.expect.section('@b').to.not.be.present;
// If I try to 'expect' on an 'element' rather than a section, it suffers the same fate as above:
myPage.section.a.section.b.expect.element('@c').to.not.be.present;
// If I try to use 'waitForElementNotVisible' instead of 'expect', it still fails:
myPage.section.a.section.b.waitForElementVisible('@c');
The reason I think that the fact that I'm using sections is significant is because if I add an element at the page's root that points to the element I'm after (and change the test accordingly), the hanging and exception seem to go away:
// myPage.js
module.exports = {
sections: {
// all my same stuff here
...
},
elements: {
// Make my target an element that is not part of any sections
target: {
selector: 'a b div.target'
}
}
};
// myTest.js
// This seems to work just fine!
myPage.expect.element('@target').to.not.be.present;
Here is is the Selenium error from the logs:
10:29:08.589 INFO - Executing: [find child elements: 41 [[[[ChromeDriver: chrome on MAC (6ac35cd44307d6f023cf0f947b90c386)] -> css selector: section div div.modal-container]] -> css selector: form], By.cssSelector: header.modal-header])
10:29:19.343 WARN - Exception thrown
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 70 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'polaris.local', ip: '10.0.0.233', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=/var/folders/b3/yl814bh52gjd21rbs701h06r0000gn/T/.org.chromium.Chromium.mGjwWi}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=61.0.3163.100, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 6ac35cd44307d6f023cf0f947b90c386
*** Element info: {Using=css selector, value=header.modal-header}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:214)
at org.openqa.selenium.remote.RemoteWebElement.findElementsByCssSelector(RemoteWebElement.java:291)
at org.openqa.selenium.By$ByCssSelector.findElements(By.java:441)
at org.openqa.selenium.remote.RemoteWebElement.findElements(RemoteWebElement.java:190)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement$1.invoke(EventFiringWebDriver.java:335)
at com.sun.proxy.$Proxy2.findElements(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.findElements(EventFiringWebDriver.java:417)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openqa.selenium.remote.server.KnownElements$1.invoke(KnownElements.java:64)
at com.sun.proxy.$Proxy3.findElements(Unknown Source)
at org.openqa.selenium.remote.server.handler.FindChildElements.call(FindChildElements.java:49)
at org.openqa.selenium.remote.server.handler.FindChildElements.call(FindChildElements.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
10:29:39.364 WARN - Exception: stale element reference: element is not attached to the page document
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 70 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'polaris.local', ip: '10.0.0.233', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=/var/folders/b3/yl814bh52gjd21rbs701h06r0000gn/T/.org.chromium.Chromium.mGjwWi}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=61.0.3163.100, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 6ac35cd44307d6f023cf0f947b90c386
*** Element info: {Using=css selector, value=header.modal-header}
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
Nightwatch: 0.9.16
Node: v6.11.1
OS: 10.12.6 (OSX Sierra)
Hi there,
My issue is quite similar to #687 and #642 . However, I'm unable to rectify it. It only happens "sometimes" so it's clearly some sort of race condition as to whether the bug occurs, but I believe this is a bug and is not the expected behavior. Expected behavior would be for nightwatch to not care about stale elements Exceptions, and only determine if the test/expectation is met or not within the timeout period. This is the assumed behavior in the other tickets as well.
I think the significant difference between my scenario and the scenarios accounted for and/or fixed in the other issues may be that my scenario is targeting
section
elements and/orelements
underneath sections. Let me explain with some code:sections
is significant is because if I add an element at the page's root that points to the element I'm after (and change the test accordingly), the hanging and exception seem to go away:Here is is the Selenium error from the logs:
The text was updated successfully, but these errors were encountered: