简体   繁体   English

有什么办法我们也可以使用wedriver截取整个页面的屏幕截图,包括向下的页面(滚动条)

[英]Is there any way we can also take the screenshot of entire page including the page which is there in down (scrollbar) using wedriver

I need to capture the full page of IE browser. 我需要捕获IE浏览器的整个页面。 I am using web driver. 我正在使用网络驱动程序。 Pls help me. 请帮助我。

below code is used to capture the present window only. 下面的代码仅用于捕获当前窗口。

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

You can change the browser to full screen before taking the screenshot. 您可以在截屏之前将浏览器更改为全屏显示。 This is the code: 这是代码:

private void changeToFullScreen() {
    try {
        Robot r;
        r = new Robot();
        r.keyPress(java.awt.event.KeyEvent.VK_F11);
        r.keyRelease(java.awt.event.KeyEvent.VK_F11);
        driver.sleep(2);
    } catch (AWTException e) {
        log.error("It was not possible to maximize", e)
        driver.manage().window().maximize();
    }
}

If you don't want to change the screen size, you can obtain the browser height and take screenShots while you scroll down until the bottom (can be done with Robot): 如果您不想更改屏幕尺寸,则可以获取浏览器高度并在向下滚动到底部时获取screenShots(可以通过Robot进行):

int numberOfScrolls = pageHeight / browserHeight;
for(int i = 0 ; i < numberOfScrolls ; i++){
   takeScreenshot();
   scrollDown(browserHeight);
}
concatenateScreenshots();
import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

public class TakeScreenshotWithScroll {
    static WebDriver driver;
    public static void main(String args[]) throws Exception{
        String key = "webdriver.gecko.driver";
        String value = "driver/geckodriver.exe";
        driver = new FirefoxDriver();
        System.setProperty(key, value);
        driver.get("ENTER THE URL HERE");
        Thread.sleep(2000);
        Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
        ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
    }
}

Here is the download link of aShot Jar file 这是aShot Jar文件的下载链接

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

相关问题 如何截取整个网页的屏幕截图? - How can I take a screenshot of a whole web page? Selenium:无法使用 aShot 库截取完整的页面截图 - Selenium: Not able to take complete page screenshot using aShot library 如何使用 web 驱动采样器 JMeter 和 java 和 selenium wedriver 上下滚动到任何元素 - How to scroll up and down to any element using web driver sampler JMeter and java and selenium wedriver 用Java中的URL截屏的任何方法 - Any way to take screenshot of URL in java 无法获取浏览器全屏截图 - Unable to take browser full page screenshot 使用 Selenium 在 Chrome 中获取整页屏幕截图 - Take full page screenshot in Chrome with Selenium 是否有任何库我们可以在recyclerview中获得marquee效果(例如hotstar vip页面滚动图像)? - Is there any library from which we can we get marquee effect in recyclerview(e.g hotstar vip page scrolling images)? 如何使用 selenium 获取整页屏幕截图,包括可滚动弹出窗口的所有内容 - How to get full page screenshot including all the content of scrollable popup using selenium 如何使用 JXBrowser 捕获特定元素而不是整个页面的屏幕截图? - How to capture the screenshot of a specific element rather than entire page using JXBrowser? 是否可以使Intranet用户通过浏览器获取当前页面的屏幕截图? - Can I enable intranet users to take screenshot of the current page via the browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM