简体   繁体   English

Firefox开发人员工具的多个屏幕截图

[英]Multiple screenshot with Firefox Developer Tools

I am trying take screenshots of a page that loads a series of content (slideshow) via Javascript. 我正在尝试拍摄通过Java脚本加载一系列内容(幻灯片)的页面的屏幕截图。 I can take screenshots of individual items with Firefox Devtools just fine. 我可以使用Firefox Devtools截取单个项目的屏幕截图。 However it's tedious to do so by hand. 但是,手工这样做很麻烦。

I can think of a few options- 我可以想到一些选择

  1. Run the 'screenshot' command in a loop and call a JS function in each loop to load the next content. 在循环中运行“ screenshot”命令,并在每个循环中调用JS函数以加载下一个内容。 However I can't find any documentation to script the developer tools or call JS functions from within it. 但是,我找不到任何文档来编写开发人员工具的脚本或从中调用JS函数。

  2. Run a JS script on the page to load the contents at an interval and call the devtools to take a screenshot each time. 在页面上运行JS脚本,以一定时间间隔加载内容,并每次调用devtools截屏。 But I can't find any documentation on calling devtools from JS in webpage. 但是我找不到网页上有关从JS调用devtools的任何文档。

  3. Have Devtools take screenshots in response to a page event. 让Devtools截屏以响应页面事件。 But I can't find any documentation on this either. 但是我也找不到任何文档。

How do I do this? 我该怎么做呢?

Your first questions is, how to take screenshots with javascript in a programmed way: use selenium Webdriver to steer the browser instead of trying to script the developer tools of a specific browser. 您的第一个问题是,如何以编程方式使用javascript截屏:使用selenium Webdriver操纵浏览器,而不是尝试编写特定浏览器的开发人员工具的脚本。

Using WebdriverJS as framework you can script anything you need around the Webdriver itself. 使用WebdriverJS作为框架,您可以围绕Webdriver本身编写所需的任何脚本。

Your second question is, how to script the FF dev tools: - no answer from my side - 您的第二个问题是,如何编写FF开发工具的脚本:-我这边没有答案-

I will second Ralf R's recommendation to use webdriver instead of trying to wrangle the firefox devtools. 我将赞同Ralf R的建议,即使用webdriver而不是试图破坏firefox devtools。

Here's a webdriverjs script that goes to a webpage with a slow loading carousel, and takes a screenshot as soon as the image I request is fully loaded (with this carousel, I tell it to wait until the css opacity is 1). 这是一个webdriverjs脚本,该脚本会转到一个加载缓慢的轮播的网页,并在我请求的图像完全加载后立即截屏(使用该轮播,我告诉它等到css的opacity为1)。 You can just loop this through however many slide images you have. 您可以遍历所有幻灯片图像。

var webdriver = require('selenium-webdriver');
var By = webdriver.By;
var until = webdriver.until;
var fs = require("fs");
var driver = new webdriver.Builder().forBrowser("chrome").build();

//Go to website
driver.get("http://output.jsbin.com/cerutusihe");

//Tell webdriver to wait until the opacity is 1
driver.wait(function(){
  //first store the element you want to find in a variable.
  var theEl = driver.findElement(By.css(".mySlides:nth-child(1)"));
  //return the css value (it can be any value you like), then return a boolean (that the 'result' of the getCssValue request equals 1)
  return theEl.getCssValue('opacity').then(function(result){
    return result == 1;
  })
}, 60000) //specify a wait of 60 seconds.

//call webdriver's takeScreenshot method.
driver.takeScreenshot().then(function(data) {
  //use the node file system module 'fs' to write the file to your disk. In this case, it writes it to the root directory of my webdriver project.
  fs.writeFileSync("pic2.png", data, 'base64');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM