【发布时间】:2022-01-06 13:15:41
【问题描述】:
代码:
try {
driver.findElement(By.xpath("//div/table[@class='v-table-table']/descendant::tr/td[1])").click();
} catch(StaleElementReferenceException e) {
// some code
}
此代码在本地运行良好,异常由 catch 块处理,我的代码继续执行,但是当我在 Jenkins 上运行相同的代码时,catch 块无法捕获异常。
Found Element By : By.xpath: //div/table[@class='v-table-table']/descendant::tr/td[1]
日志:
Exception occured: org.openqa.selenium.StaleElementReferenceException: The element reference of <td class="v-table-cell-content"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'seliius26226', ip: 'a.b.c.d', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.5.2.el7.x86_64', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 78.9.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20210315154203, moz:geckodriverVersion: 0.26.0, moz:headless: true, moz:processID: 10789, moz:profile: /tmp/rust_mozprofileca5iLw, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, platformVersion: 3.10.0-693.5.2.el7.x86_64, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: fefe7087-15e4-4b59-b908-55837803641b
Exception occured: org.openqa.selenium.WebDriverException: java.io.IOException: No such file or directory
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'seliius26226', ip: 'a.b.c.d', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.5.2.el7.x86_64', java.version: '1.8.0_151'
Driver info: driver.version: EventFiringWebDriver
【问题讨论】:
-
尝试:catch (Exception e) { if (e.getClass().getCanonicalName().equals("org.openqa.selenium.StaleElementReferenceException"))...
-
这不起作用我得到同样的错误
-
您可能只想将 Selenium 从 3.14 升级到 3.141。
-
如果版本是问题,那么它也不应该在本地运行
-
@pcalkins 请看看这个stackoverflow.com/q/70260972/17543864
标签: java linux selenium jenkins testing