[英]Is there a way to capture the screenshot of specific elementID on Android screen in Appium using Selenium (Java)?
I am trying to capture the screenshot of only a part of Android screen specific to an element ID.我正在尝试仅捕获特定于元素 ID 的 Android 屏幕的一部分的屏幕截图。 Not the whole screen.不是整个屏幕。
I don't know what is your specific context, any way to get a screenshot of an image represented in a <img>
HTML, some times ago I used this code in one of my projects.我不知道您的具体上下文是什么,以任何方式获取以<img>
HTML 表示的图像的屏幕截图,前一段时间我在我的一个项目中使用了此代码。 Hope this could help and could be similar to your situation希望这会有所帮助,并且可能与您的情况相似
WebDriver drv2 = new ChromeDriver();
drv2.get("https://www.example.com");
WebElement el = drv2.findElement(By.xpath("//img[@src='/page.php']"));
File SrcFile = el.getScreenshotAs(OutputType.FILE);
File DestFile = new File("/your/path/file.png");
Files.copy(SrcFile.toPath(),DestFile.toPath());
where the HTML tag was something like HTML 标记的位置类似于
<img src="page.php" />
Change //img[@src='/page.php']
with your HTML tags info.使用您的 HTML 标签信息更改//img[@src='/page.php']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.