0

I am using driver.findelements(By.xpath("//*)); to retrive all the elements on the page, however, on IE9/IE10, I am getting a stale element exception. How do I handle it? Please help me.

Error is listed below:

Started InternetExplorerDriver server (32-bit)
2.33.0.0
Listening on port 40366
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager).
log4j:WARN Please initialize the log4j system properly.
I am in IE
Scanning Web objects....Please be patient
org.openqa.selenium.StaleElementReferenceException: Element is no longer valid (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 750c270f-ce8d-4d46-b6fb-6944183dbbd9
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=9, cssSelectorsEnabled=true, ignoreProtectedModeSettings=true, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, browserAttachTimeout=0, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:123)
at com.util.browser.browser_type.getobjects(browser_type.java:225)
at com.util.browser.browser.main(browser.java:57)
--Arr SIze===>24
theblindprophet
  • 7,767
  • 5
  • 37
  • 55
user2617199
  • 3
  • 2
  • 4
  • The stack trace isn't going to help us at all. Stale element exceptions happen when you perform an action on an element that has changed, NOT when you find an element. However, that said...I'm not sure why you are trying to find every element on the page. – Nathan Merrill Sep 05 '13 at 19:25
  • Can you show more of your selenese? The relevant html? If the webpage is live on the web, even a url would be helpful. The question as is, doesn't tell us very much. Also, you are missing a quotation mark to close the locator `String` in your `By`. – Dingredient Sep 05 '13 at 19:58

1 Answers1

0

So it looks like, from the stack trace, your driver is only waiting 15MS. That's too short. Try:

wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

At least when you are running on IE. That said I'm afraid that this issue is actually a flaw in the way that the IE driver is built. Have a look at this thread:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCsQFjAA&url=https%3A%2F%2Fgroups.google.com%2Fd%2Ftopic%2Fselenium-developers%2FuJ5z8aJ2X6Y&ei=RJSCUu_zPIWXiAKkuICYDg&usg=AFQjCNGjmmMjEqKa0bwLQZfLfuHIBXR-rQ&bvm=bv.56343320,d.cGE

and this and other very painful hackarounds to this problem...

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CDQQFjAB&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F16166261%2Fselenium-webdriver-stale-element-reference-exception&ei=RJSCUu_zPIWXiAKkuICYDg&usg=AFQjCNEbFBbpDr0geAtA5rWiPvrCiNeUTg&bvm=bv.56343320,d.cGE

I suspect that the IE driver is simply under supported.

Aaron Cooley
  • 1,967
  • 15
  • 11