2
참고 : 몇 시간 전에이 질문에 대한 답변을 얻었지만 다른 사람들이 가지고 있지 않은 것 같은 문제가 있음을 알고 있습니다.Screenshot Selenium의 특정 요소
요소의 포인트가 폭과 높이와 정확하게 일치하는 것처럼 보일지라도 최종 자르기가 잘못되었습니다. 그것은 내가 찍고있는 스크린 샷이 웹 페이지와 다른 차원을 가지고있는 것과 같습니다. 크롬 드라이버를 사용하고 있습니다.
이것은 구글 로고 이미지의 스크린 샷 얻기 위해 시도 내 코드입니다: 여기
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
WebElement ele = driver.findElement(By.id("hplogo"));
//Get entire page screenshot
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = null;
try {
fullImg = ImageIO.read(screenshot);
} catch (IOException e) {
}
//Get the location of element on the page
Point point = ele.getLocation();
//Get width and height of the element
int eleWidth = ele.getSize().getWidth();
int eleHeight = ele.getSize().getHeight();
//Crop the entire page screenshot to get only element screenshot
BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth,
eleHeight);
try {
ImageIO.write(eleScreenshot, "png", screenshot);
} catch (IOException e) {
}
//Copy the element screenshot to disk
File screenshotLocation = new File("/Users/M/Desktop/stuff/logo.png");
try{
FileUtils.copyFile(screenshot, screenshotLocation);
}catch(IOException e){
}
는 것처럼 (점점해야합니다 것입니다 GIF가 아닌 PNG) :
어떤 일이 벌어지고 있는지 알 수있는 사람이 있습니까?
틀린 이미지가 나옵니까? 나 때문에 코드가 완벽하게 작동하기 때문에 – Madhan
예, 질문에 이미지를 게시했습니다. 나는 여러 다른 요소들에 대해서도 시도했다. 그것은 정말로 나를 혼란스럽게합니다. Chrome 드라이버를 사용하고 있었습니까? Selenium의 어떤 버전을 사용하고 있습니까? @Madhan – Mitchell
너비와 높이가 적당히 높아지고 있지만 스크린 샷의 확대 또는 확대와 비슷합니까? 그것은 스크린 샷의 너비와 높이와 같으며 웹 페이지와 다릅니다. – Mitchell