我使用带有 Ashot 框架的 Selenium 来制作整个页面的屏幕截图
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
这个拍摄策略效果很好,我可以得到全尺寸的截图。我收到了我网页的 1200 宽度 x 全尺寸的屏幕截图,但我需要用不同的宽度尺寸来截图我的网页,例如,1920xFullSize、1280xFullSize 等。我尝试使用 Dimension 来精确设置宽度:
Dimension d = new Dimension(1920,720 );
driver.manage().window().setSize(d);
但如果我使用 Dimension,则整个垂直尺寸的屏幕截图不起作用,我会收到 1920x720 的图像。
如何截取 1920xFullSize、1280xFullSize 等?