@naveen 일반적으로 Chrome 브라우저에서 발생합니다. ChromeDriver는 보이는 부분의 스크린 샷을 찍을 수 있습니다. 따라서 여기서는 Java 스크립트 실행 프로그램을 사용하여 페이지를 스크롤하여 여러 이미지를 가져온 다음 단일 이미지에 결합합니다. FirefoxDriver는 문제없이 전체 화면의 이미지를 찍을 수 있습니다. 여기에 당신이 도움이 here를 찾을 수있는 모든 이미지 파일을 결합하는 예
@Test(enabled=true)
public void screenShotExample() throws IOException{
//WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "yourpath to chromeDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.w3schools.com/");
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
JavascriptExecutor jexec = (JavascriptExecutor)driver;
jexec.executeScript("window.scrollTo(0,0)"); // will scroll to (0,0) position
boolean isScrollBarPresent = (boolean)jexec.executeScript("return document.documentElement.scrollHeight>document.documentElement.clientHeight");
long scrollHeight = (long)jexec.executeScript("return document.documentElement.scrollHeight");
long clientHeight = (long)jexec.executeScript("return document.documentElement.clientHeight");
int fileIndex = 1;
if(driver instanceof ChromeDriver){
if(isScrollBarPresent){
while(scrollHeight > 0){
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
jexec.executeScript("window.scrollTo(0,"+clientHeight*fileIndex++ +")");
scrollHeight = scrollHeight - clientHeight;
}
}else{
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
}
}else{
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(srcFile, new File("F://MyFile"+ fileIndex+".jpg"));
}
// Combine all the .jpg file to single file
driver.close();
driver.quit();
}
입니다. 희망이 당신을 도울 것입니다.
사용중인 드라이버 (브라우저)는 무엇입니까? –
모질라를 사용하고 있습니다 – naveen