是否有可能使用硒web驅動程序捕獲網絡用戶界面的特定部分(如使用圖像的座標?不是整個頁面!)?我用java寫我的腳本。謝謝屏幕截圖使用硒webdriver的網絡的一部分
-1
A
回答
0
想和大家分享我如何使用Multiscreenshot罐子解決了這個問題。謝謝。
import multiScreenShot.MultiScreenShot;
WebElement object1 = driver.findElement(By.Id("MyObject"));
object1.click();
MultiScreenShot multiScreens = new MultiScreenShot("C:\\", "test"); // Path where you save the image
multiScreens.elementScreenShot(driver, object1);
WebElement object2 = driver.findElement(By.Id("YourObject"));
object2.click();
multiScreens.elementScreenShot(driver, object2);
0
我認爲這部分代碼會幫助你。
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 = ImageIO.read(screenshot);
// 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);
ImageIO.write(eleScreenshot, "png", screenshot);
// Copy the element screenshot to disk
File screenshotLocation = new File("C:\\images\\GoogleLogo_screenshot.png");
FileUtils.copyFile(screenshot, screenshotLocation);
+0
這對我來說很好。我覺得這會對我的項目起作用。感謝@Lucky的幫助。 –
相關問題
- 1. 屏幕截圖與IE8上的硒webdriver
- 2. Webdriver屏幕截圖
- 3. 屏幕部分的屏幕截圖
- 4. Webdriver的屏幕截圖
- 5. 硒網格,捕捉屏幕截圖
- 6. 使用硒自動屏幕截圖
- 7. 如何捕獲使用硒webdriver的網頁的截屏?
- 8. 通過網絡發送屏幕截圖
- 9. html2canvas外部網站的屏幕截圖
- 10. Swift 3的部分屏幕截圖
- 11. Selenium:使用硒網格存儲屏幕截圖
- 12. 僅截取表單的一部分屏幕截圖?
- 13. 採取屏幕的特定部分的屏幕截圖
- 14. SpriteKit屏幕截圖的屏幕截圖
- 15. 使用GTK的屏幕分區的屏幕截圖
- 16. 在C中使用selenium webdriver截取屏幕截圖時的空白截圖#
- 17. 從底部截取的主屏幕網絡應用程序
- 18. Phantomjs - 截取網頁的屏幕截圖
- 19. 如何截取Pygame屏幕中的某個部分的屏幕截圖
- 20. 部分屏幕截圖與鉻
- 21. Selenium Webdriver Black屏幕截圖PhantomJS
- 22. Mac:屏幕截圖選擇實施? (選擇屏幕的一部分的能力)
- 23. 適用於網絡瀏覽器的最佳屏幕截圖API
- 24. 如何獲取網絡應用程序的屏幕截圖
- 25. 在C#中使用Selenium Webdriver的當前窗口屏幕截圖#
- 26. 硒測試保存屏幕截圖
- 27. 以多屏幕截圖硒和java
- 28. 在硒中捕獲屏幕截圖
- 29. 使用硒腳本的空白屏幕截圖
- 30. Android屏幕截圖底部
不是開箱即用的。相反,截取整個頁面,獲取所需元素的邊界和座標並相應地裁剪圖像。 – qqilihq
感謝您的回覆@qqilihq –
@jainishkapadia我相信您分享的鏈接正在瀏覽整個網頁。我擔心的是多個屏幕截圖是網頁的一部分或內部(可能位於隨機位置)。 –