java - 无法使用 selenium webdriver 完全剪切宽横幅图像,仅剪切图像的一部分
问题描述
我正在尝试使用 selenium webdriver java 从 iframe 中的网页中剪切宽横幅图像,但使用以下代码剪切后我只能获得部分横幅图像。
我试过下面的代码 wghich 只给了我部分横幅图像。
WebElement element = driver.findElement(By.xpath("//amp-
img[@class='img_ad
i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-element
i-amphtml-layout']//img[@class='i-amphtml-fill-content i-amphtml-
replaced-content']"));
File screen = ((TakesScreenshot)
driver).getScreenshotAs(OutputType.FILE);
Point point = element.getLocation();
int xcordinate = point.getX();
int ycordinate = point.getY();
int imageWidth = element.getSize().getWidth();
int imageHeight = element.getSize().getHeight();
BufferedImage img = ImageIO.read(screen);
BufferedImage destination = img.getSubimage(xcordinate, ycordinate,
imageWidth, imageHeight);
ImageIO.write(destination, "png", screen);
File screenshotLocation = new
File("C:\\shots\\screenshotOfElement.png");
FileUtils.copyFile(screen,screenshotLocation);
请让我知道我应该在我的代码中进行哪些更改以在使用上述代码剪切后获得完整的横幅图像。
解决方案
推荐阅读
- ios - 如何将结构发送到 BLE 写入值?
- swift - UISearchController - 搜索用户 - 表格视图为空白?Firebase/Swift
- angularjs - 无法将参数发送到 Spring get 方法
- go - 自定义模板/十六进制值的 ASCII 转换
- java - 春天返回json
- python - 按组 id 从最后 n 行获取值的总和
- c++ - Eigen:模板化函数中矩阵的平面视图
- wordpress - 如何使 mysql 访问公开,而不仅限于本地主机?
- adobe - 创建自定义自适应表单组件 - 将提交和存储数据
- spring-boot - 如何在几个 Spring Boot `FailureAnalyzer` 之间指定相对顺序或优先级?