【问题标题】:grabAttributeFrom() method not returning the attribute valuegrabAttributeFrom() 方法不返回属性值
【发布时间】:2020-03-26 18:10:17
【问题描述】:

我正在尝试使用I.grabAttributeFrom() 方法获取元素的属性值,但我总是得到未定义而不是属性值。我的代码是

Scenario('Smoketest', async (I) => {

const columnIndex = await I.grabAttributeFrom('//th[text()="Status"]', 'aria-colindex');

});

元素是这样的

<th aria-colindex = "2">
"Status"
<span> ... </span>
</th>

我在 codeceptjs 中使用 testcafe。

【问题讨论】:

  • 我把你的选择器改成了th,还是不行。我调试了testcafe 模块,它按预期工作:返回值2。问题可能出在codeceptjs 方面。在他们的 github 存储库中报告它是有意义的。
  • 感谢您向我确认这不是 testcafe 问题。我会检查 codeceptjs github repo。
  • 修复已合并。现在等待下一个(2.4.0)版本。感谢发现错误
  • 欢迎。我会检查下一个版本:)

标签: testing attributes automated-tests testcafe codeceptjs


【解决方案1】:

我也无法让它工作,所以我写了一个量角器助手来帮助我获取文本属性:

  /**
   * Function to return the text content of all elements matching with the locator in an array
   * @param xpath object
   */
  async getElementsText(locator) {
    const driver = this.helpers.Protractor.browser;
    await driver.waitForAngular();
    // await console.log("Getting text for: " + locator.xpath);
    return driver.element.all(by.xpath(locator.xpath)).getAttribute("textContent");
  }

【讨论】:

    猜你喜欢
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 2023-03-09
    • 2020-07-07
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多