【问题标题】:Selenium code works fine on localhost but unable to catch the StaleElementReferenceException on JenkinsSelenium 代码在 localhost 上运行良好,但无法在 Jenkins 上捕获 StaleElementReferenceException
【发布时间】: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


【解决方案1】:

您的 java.version: '1.8.0_151' 太旧了。

JDK 更新到当前级别 JDK 8u311 并执行您的测试。


更新

错误错误堆栈跟踪还提到:

[GC (Allocation Failure)  56810K->10231K(139776K), 0.0097259 secs]

GC (Allocation Failure)是GC循环启动的效果。

分配失败意味着没有更多空间可以分配对象。较旧的 JVM 不会为次要 GC 周期打印 GC 原因。 分配失败几乎是次要 GC 的唯一可能原因。启动次要 GC 的另一个原因可能是 CMS 备注阶段(如果启用了 +XX:+ScavengeBeforeRemark)。

【讨论】:

  • 我的本地机器上安装了相同的 JDK,但它在那里工作
  • @TARUNYADAV 查看更新的答案并让我知道状态。
  • 我尝试了这个解决方案,我没有得到 GC 分配失败,但仍然没有捕获到异常
  • @TARUNYADAV 可能在您尝试捕捉时没有发生异常...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-16
相关资源
最近更新 更多