0

我正在使用 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
4

1 回答 1

0

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

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

以及这个问题和其他非常痛苦的解决方法......

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-元素引用异常&ei=RJSCUu_zPIWXiAKkuICYDg&usg=AFQjCNEbFBbpDr0geAtA5rWiPvrCiNeUTg&bvm=bv.56343320,d.cGE

我怀疑 IE 驱动程序根本不支持。

于 2013-11-12T21:11:56.457 回答