Когда я меняю среду с Windows 10 на Ubuntu , и некоторые функции не работают.Как эта функция снимать скриншот
Пожалуйста, помогите мне найти решение сделать снимок экрана в Ubuntu.Когда я делаю скриншот на Ubuntu, я думаю, что это неправильная позиция элемента.Спасибо
Работа для Windows 10
public void captureElementScreenshot(WebElement element, String fileName) {
//Capture entire page screenshot as buffer.
//Used TakesScreenshot, OutputType Interface of selenium and File class of java to capture screenshot of entire page.
File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
//Used selenium getSize() method to get height and width of element.
//Retrieve width of element.
int ImageWidth = element.getSize().getWidth();
//Retrieve height of element.
int ImageHeight = element.getSize().getHeight();
//Used selenium Point class to get x y coordinates of Image element.
//get location(x y coordinates) of the element.
Point point = element.getLocation();
int xcord = point.getX();
int ycord = point.getY();
//Reading full image screenshot.
BufferedImage img = null;
try {
img = ImageIO.read(screen);
BufferedImage dest = img.getSubimage(xcord, ycord, ImageWidth, ImageHeight);
ImageIO.write(dest, "png", screen);
//Used FileUtils class of apache.commons.io.
//save Image screenshot In D: drive.
FileUtils.copyFile(screen, new File(System.getProperty("user.dir") + "//src//test//screenshot//" + fileName + ".png"));
System.out.println("Success save file " + fileName);
} catch (IOException e) {
e.printStackTrace();
}
//cut Image using height, width and x y coordinates parameters.
}
И этот конфигурационный браузер
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "//src//test//browser//chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("force-device-scale-factor=0.75");
options.addArguments("high-dpi-support=0.75");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();