简体   繁体   English

有没有办法使用Selenium(Java)在Appium中的Android屏幕上捕获特定elementID的屏幕截图?

[英]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.

相关问题 屏幕截图中的appium硒中的Java代码 - screenshot java code in appium selenium 如何使用 Selenium Java 使用 Krypton 捕获屏幕截图 - How to capture a screenshot using Krypton using Selenium Java Selenium Webdriver-使用机器人捕获屏幕快照中的URL - Selenium Webdriver - Capture URL in screenshot using Robot 在本机android应用的appium中使用findElementById(“ elementID”)。 错误:“不支持定位器策略&#39;css选择器” - Using findElementById(“elementID”) with appium for native android app. Error: “Locator strategy 'css selector” is not supported" 使用appium捕获Android屏幕截图 - Capturing Android screenshot with appium 无法捕获硒中的屏幕截图 - Unable to capture screenshot in selenium 如何使用Java在Selenium2中捕获屏幕截图,需要在最小化浏览器时捕获带有其父窗口(浏览器)的弹出窗口 - How to capture Screenshot in Selenium2 using Java, need to capture popup window with its parent window(Browser) when browser is minimized Selenium Appium Java Android Chrome浏览器 - Selenium Appium Java Android Chrome Browser 屏幕捕获的更快方法(java) - Faster way of screen capture (java) 如何通过Selenium,appium,java和android以更快的方式多次点击元素 - How to tap on an element multiple times in a faster way through selenium, appium, java and android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM