gpt4 book ai didi

java - 如何通过 Selenium 和 Java 使用 AShot 库截取整页截图

转载 作者:行者123 更新时间:2023-12-05 00:48:22 25 4
gpt4 key购买 nike

我尝试了下面的代码来截取整页截图。但只捕获可见区域,

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());
}
}

最佳答案

使用 Selenium Java Client v3.14.0ChromeDriver v2.41Chrome v 68.0 使用 ashot-1.4。 4.jar 这里是使用 ChromeDriveraShot Library完整页面截图 的示例em>url https://jquery.com/:

  • 代码块:

    import java.io.File;
    import javax.imageio.ImageIO;
    import org.openqa.selenium.WebDriver;
    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 ru.yandex.qatools.ashot.shooting.ShootingStrategies;

    public class ashot_CompletePage {

    public static void main(String[] args) throws Exception {

    System.setProperty("god.bless.you", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.addArguments("disable-infobars");
    options.addArguments("--disable-extensions");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://jquery.com/");
    new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("jQuery"));
    Screenshot myScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
    ImageIO.write(myScreenshot.getImage(),"PNG",new File("./Screenshots/elementScreenshot.png"));
    driver.quit();
    }
    }
  • 截图:

screenshot


引用

您可以在 How to take screenshot with Selenium WebDriver 中找到详细讨论。

关于java - 如何通过 Selenium 和 Java 使用 AShot 库截取整页截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51893208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com