seleniumQuery / seleniumQuery

jQuery-like cross-driver interface in Java for Selenium WebDriver
http://seleniumquery.github.io/
Other
71 stars 25 forks source link

StaleElementException after clicking an element #133

Closed jordiponsllaurado closed 8 years ago

jordiponsllaurado commented 8 years ago

After clicking on some button, the element is already clicked, but the method throws a StaleElementException. This is reproducible on only some buttons in the page, but not on all of them.

I use a css selector that is unique in order to ensure that I click on the correct button.

The curious thing is that the Exception is thrown AFTER clicking the button, so the element is actually used.

This is the Stacktrace:

Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_72'
Driver info: driver.version: unknown
Command duration or timeout: 3.43 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_72'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=38.4.0, platform=MAC, nativeEvents=false, acceptSslCerts=true, webdriver.remote.sessionid=b76c649d-22d3-487a-8ba8-51a463afc67d, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: b76c649d-22d3-487a-8ba8-51a463afc67d
    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:647)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:326)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at io.github.seleniumquery.functions.jquery.events.ClickFunction.click(ClickFunction.java:47)
    at io.github.seleniumquery.SeleniumQueryObject.click(SeleniumQueryObject.java:321)
    at biz.netcentric.at.selcq.spi.tools.InteractionHelper.clickAndWait(InteractionHelper.java:34)
    at biz.netcentric.at.selcq.spi.tools.InteractionHelper.clickAndWait(InteractionHelper.java:30)
    at biz.netcentric.at.selcq.frontends.touchui.PageCreatorImpl.createPage(PageCreatorImpl.java:23)
    at biz.netcentric.at.selcq.frontends.touchui.Sites.createPage(Sites.java:77)
    at biz.netcentric.at.selcq.impl.WebsitesImpl.createPage(WebsitesImpl.java:60)
    at biz.netcentric.at.selcq.CreatePageTest.createPageWithParametersTest(CreatePageTest.java:48)
    ... 23 more
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_72'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:138)
    ... 34 more
Caused by: org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_72'
Driver info: driver.version: unknown
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_72'
Driver info: driver.version: unknown
    at <anonymous class>.fxdriver.cache.getElementAt(resource://fxdriver/modules/web-element-cache.js:9351)
    at <anonymous class>.Utils.getElementAt(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:8978)
    at <anonymous class>.fxdriver.preconditions.visible(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:9979)
    at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12517)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)
    at <anonymous class>.DelayedCommand.prototype.execute/<(file:///var/folders/wf/94b1wttd0v1b6t0md1pkllp80000gn/T/anonymous2009414429332203653webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)
acdcjunior commented 8 years ago

I assume (from the selenium version 2.48.2) you are using version0.10.0, right?

Do you get this behavior consistently (all the time) at those elements?

The curious thing is that the Exception is thrown AFTER clicking the button, so the element is actually used.

How can you tell that?

Other than that, can you provide some minimal snippet where we can reproduce the problem?

Of the top of my head, I'd suggest you update the version (which updates the selenium version as well, which can impact supported browser versions).

jordiponsllaurado commented 8 years ago

We are using version 0.13.0 and we tried again using selenium version 2.52.0 with firefox (version 38.7.0 esr) and the error persists.

The html element is this: <a class="endor-List-item endor-List-item--interactive cq-siteadmin-admin-createpage coral-Link" href="/libs/wcm/core/content/sites/createpagewizard.html/content/geometrixx-outdoors/en/unittest/test">Create Page</a>

We perform the click using this: $(".cq-siteadmin-admin-createpage").click()

See the video attached to see what is happening, the element that is throwing an excepetion is this:

screen shot 2016-03-09 at 09 03 26

Attached gif: automated-test-video-seleniumquery

acdcjunior commented 8 years ago

Can you print the .size() of the .click()ed object, right before clicking it?

Maybe there is another element that becomes stale (e.g. it is removed) after the selection, but before the lib gets a chance to click it.

jordiponsllaurado commented 8 years ago

After doing .size() we realised that for some reason there where more than one element with the same selector.

Thanks for your help and your time, I will close the issue.