我尝试了下面的代码来截取整个页面的截图。但只捕捉到了可见区域,
public void Fullscreen (WebDriver driver)
{
try {
final Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", new File("D:\\" + "AShot_BBC_Entire.png"));
} catch(Exception e){
System.out.println(e.getMessage());
}
}
发布于 2018-08-17 18:58:58
在使用ashot-1.4.4.jar使用Selenium Java Client v3.14.0、ChromeDriver v2.41、Chrome v68.0时,这里是一个使用ChromeDriver和url https://jquery.com/
的aShot库在水平和垂直方向上拍摄完整页面截图的示例
import org.openqa.selenium.support.ui.ExpectedConditions;import ru.yandex.qatools.ashot.shooting.ShootingStrategies;;import java.io.File;import javax.imageio.ImageIO;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.chrome.ChromeOptions;import org.openqa.selenium.support.ui.ExpectedConditions;import org.openqa.selenium.support.ui.WebDriverWait;import ru.yandex.qatools.ashot.AShot;import ru.yandex.qatools.ashot.Screenshot;import"C:\Utility\BrowserDrivers\chromedriver.exe");ashot_CompletePage { public static void main(String[] args)抛出异常{ System.setProperty("god.bless.you",String[]驱动程序选项=新的ChromeOptions();options.addArguments(“启动最大化”);options.addArguments(“禁用信息栏”);options.addArguments(“--禁用扩展”);WebDriver驱动程序=新的ChromeDriver(选项);20).until(ExpectedConditions.titleContains("jQuery"));(“https://jquery.com/");new WebDriverWait(驱动程序,屏幕截图myScreenshot =新建屏幕截图(ImageIO.write(),"PNG",新建文件(”./https://jquery.com/"/WebDriverWait Screenshot.png“);driver.quit();}driver.get
参考文献
您可以在How to take screenshot with Selenium WebDriver中找到详细的讨论
发布于 2020-11-25 19:51:19
我想添加答案,以防您不知道使用的是哪种屏幕。(视网膜或非视网膜)
在这种情况下,您需要查找浏览器窗口的devicePixelRatio:
Object output = ((JavascriptExecutor) webDriver).executeScript("return window.devicePixelRatio");
String value = String.valueOf(output);
float windowDPR = Float.parseFloat(value);
然后您可以使用带伸缩的ShootingStrategy;
ShootingStrategy shootingStrategy = ShootingStrategies.viewportPasting(ShootingStrategies.scaling(windowDPR), 100)
https://stackoverflow.com/questions/51893208
复制相似问题