使用Java,如何处理WebDriver中的“陈旧元素异常”?

时间:2013-09-05 17:58:35

标签: java selenium-webdriver webdriver

我正在使用driver.findelements(By.xpath(“// *));要检索页面上的所有元素,但是,在IE9 / IE10上,我得到一个陈旧的元素异常。怎么做我处理了吗?请帮帮我。

错误列在下面:

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

1 个答案:

答案 0 :(得分:0)

所以看起来,从堆栈跟踪看,你的驱动程序只等待15MS。那太短了。尝试:

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

至少在IE上运行时。这就是说我担心这个问题实际上是构建IE驱动程序的一个缺陷。看看这个帖子:

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

这个和其他非常痛苦的hackarounds这个问题...

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

我怀疑IE驱动程序受到支持。