You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium Firefox135调用moveToElement出现Cyclic object value异常求助

Selenium moveToElement 触发 Cyclic object value 异常的解决办法

问题重现

执行以下代码时触发异常:

WebElement element = driver.findElement(locator);
action.moveToElement(element).perform();

错误信息如下:

Cyclic object value
Build info: version: '4.18.1', revision: 'b1d3319b48'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '11.0.2'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [d672e096-86df-4f10-b179-ad6de5606c0e, actions {actions=[org.openqa.selenium.interactions.Sequence@115a203a]}]
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 135.0.1, moz:accessibilityChecks: false, moz:buildID: 20250216192613, moz:geckodriverVersion: 0.35.0, moz:headless: false, moz:platformVersion: 24.3.0, moz:processID: 6322, moz:profile: /var/folders/v0/4rg4bfd12nq..., moz:shutdownTimeout: 60000, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platformName: mac, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, userAgent: Mozilla/5.0 (Macintosh; Int...}
Session

可行解决方案

  • 修复版本兼容性问题:当前geckodriver 0.35.0仅适配Firefox 102-115版本,而你使用的Firefox为135.0.1,版本严重不匹配。直接升级geckodriver到适配Firefox 135的版本(如0.39.0及以上),确保驱动与浏览器版本对应。
  • 重新初始化Actions对象:避免复用旧的Actions实例,每次执行悬停操作前重新创建:
    WebElement element = driver.findElement(locator);
    Actions action = new Actions(driver);
    action.moveToElement(element).perform();
    
  • 用JavaScript模拟悬停:若Actions方法仍报错,改用JS执行替代:
    WebElement element = driver.findElement(locator);
    String jsScript = "var evt = document.createEvent('MouseEvents'); evt.initMouseEvent('mouseover',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); arguments[0].dispatchEvent(evt);";
    ((JavascriptExecutor) driver).executeScript(jsScript, element);
    
  • 确保元素定位有效:添加显式等待,确认元素存在且可见后再执行悬停:
    WebElement element = new WebDriverWait(driver, Duration.ofSeconds(10))
            .until(ExpectedConditions.visibilityOfElementLocated(locator));
    Actions action = new Actions(driver);
    action.moveToElement(element).perform();
    

内容的提问来源于stack exchange,提问作者prabuBJV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:42:47