【问题标题】:Expect element contains class name puppeteerExpect 元素包含类名 puppeteer
【发布时间】:2021-02-12 20:34:06
【问题描述】:

所以我有一个具有特定 id 的元素,比如说:#id = test.这个元素有一个类似 .form-thumbs-up 的类,我想断言这个元素在它的类中包含“thumbs-up”,但我不知道该怎么做。 我试过了

  const thumbsUp = await this.page.$('[id="test"]');
  const className = await thumbsUp.getProperty('className');
  expect(className).toContain('thumbs-up');

但我收到如下错误:Expected object: .... to contain value thumbs-up failed。 你知道如何解决它吗?也许我需要尝试另一种方法?

提前致谢!

【问题讨论】:

    标签: puppeteer classname


    【解决方案1】:

    getProperty 返回JS handle。你需要one more step 来获取字符串:

    const className = await (await thumbsUp.getProperty('className')).jsonValue();
    

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 1970-01-01
      • 2018-11-11
      • 2018-07-18
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      相关资源
      最近更新 更多