对该元素的边界矩形所包含的可见区域进行截图。

用法

                    browser.element(selector).takeScreenshot()
                

示例

export default {
  demoTest(browser: NightwatchAPI): void {
    const screenshot = browser.element('#main').takeScreenshot();
    screenshot.then((screenshotData) => {
      require('fs/promises').writeFile('out.png', screenshotData, 'base64');
    });
  },

  async demoTestAsync(browser: NightwatchAPI): Promise<void> {
    const screenshotData = await browser.element('#main').takeScreenshot();
    require('fs/promises').writeFile('out.png', screenshotData, 'base64');
  }
}

返回值

类型 描述
ScopedValue<string>

W3C WebDriver 规范