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

如何使用Cypress点击Chessground棋盘上的棋子

无法用Cypress触发Chessground棋盘的棋子点击事件

我正尝试使用Cypress点击Chessground棋盘上的棋子,但始终无法触发点击事件,猜测这可能与Chessground的点击绑定方式或SVG相关有关。

已尝试的方法

cy.get("cg-board")
  .should("be.visible")
  .trigger("mousedown", offset.x, offset.y, {
    force: true,
  });
cy.get("svg.cg-shapes")
  .should("be.visible")
  .trigger("mousedown", offset.x, offset.y, {
    force: true,
  });
cy.get("svg.cg-custom-svgs")
  .should("be.visible")
  .trigger("mousedown", offset.x, offset.y, {
    force: true,
  });
cy.get("div.cg-wrap")
  .should("be.visible")
  .trigger("mousedown", offset.x, offset.y, {
    force: true,
  });
cy.get("piece.white.pawn:nth(1)")
  .should("be.visible")
  .trigger("mousedown", { force: true });

cy.get("cg-board").should("be.visible").click(offset.x, offset.y, {
  force: true,
});
cy.get("svg.cg-shapes").should("be.visible").click(offset.x, offset.y, {
  force: true,
});
cy.get("svg.cg-custom-svgs")
  .should("be.visible")
  .click(offset.x, offset.y, {
    force: true,
  });
cy.get("div.cg-wrap").should("be.visible").click(offset.x, offset.y, {
  force: true,
});
cy.get("piece.white.pawn:nth(1)")
  .should("be.visible")
  .click({ force: true });

调试时的点击情况

调试时的点击情况

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 23:12:52