【问题标题】:Cypress - hover on an element inside iframe and get text of the hovered elementCypress - 悬停在 iframe 内的元素上并获取悬停元素的文本
【发布时间】:2021-03-09 13:20:18
【问题描述】:

我想自动化来自www.moneycontrol.com 网站的场景。 在主页上,有一个名为“市场行动”的部分,当我们将鼠标悬停在图表上时,我们会在其中获得一些值。像这样: Hovered Maximum Value from Graph

图表位于 iframe 内,需要始终悬停在最大值上。之后,我们需要获取悬停的值,并使用 Market Action 表头进行验证。

只需要使用 cypress 即可。我可以进入 iframe,但不确定为什么它没有在图表上单击/悬停。我的代码是这样的:

static getLatestValueByHoveringOnGraph = (): void => {
    HomePage.getMarketActionIframeBody()
      .find(".highcharts-series>path:first-child")
      .click("topRight")
      .trigger("mouseover");
  };

  private static getMarketActionIframeBody() {
    return cy
      .get("iframe[title='Indices Chart']")
      .its("0.contentDocument")
      .should("exist")
      .its("body")
      .should("not.be.undefined")
      .then(cy.wrap);
  }

几个小时以来我尝试了很多方法,但没有得到解决方案。希望有人能够解决这个问题。提前致谢。

【问题讨论】:

  • 如果有公共 API,更简单的方法是从 API 响应中获取价格。
  • 无法使用 API 作为悬停功能需要验证。

标签: iframe automation cypress ui-automation


【解决方案1】:

而不是 moveover 尝试 focus Like:

static getLatestValueByHoveringOnGraph = (): void => {
    HomePage.getMarketActionIframeBody()
      .find(".highcharts-series>path:first-child")
      .click("topRight")
      .trigger('focus');
  };

或者可以查看https://github.com/dmtrKovalenko/cypress-real-events

【讨论】:

    猜你喜欢
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多