2017-07-28 145 views

回答

-1

您可以在Java代碼中截取屏幕截圖。從這樣的回答:https://stackoverflow.com/a/3423347/8020699

WebDriver driver = new FirefoxDriver(); 
driver.get("http://www.google.com/"); 
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
// Now you can do whatever you need to do with it, for example copy somewhere 
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png")); 

This guy建議使用一個名爲阿紹特庫充分頁面截圖。這裏是鏈接到aShot jar。以下是他給出的代碼:

import java.io.File; 
import javax.imageio.ImageIO; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import ru.yandex.qatools.ashot.AShot; 
import ru.yandex.qatools.ashot.Screenshot; 
import ru.yandex.qatools.ashot.shooting.ShootingStrategies; 

public class FullPageScreenshot { 
    public static void main(String args[]) throws Exception{ 
     //Modify the path of the GeckoDriver in the below step based on your local system path 
     System.setProperty("webdriver.gecko.driver","D://Selenium Environment//Drivers//geckodriver.exe"); 
     // Instantiation of driver object. To launch Firefox browser 
     WebDriver driver = new FirefoxDriver(); 
     // To oepn URL "http://softwaretestingmaterial.com" 
     driver.get("http://www.softwaretestingmaterial.com"); 
     Thread.sleep(2000); 
     Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver); 
     ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png")); 
    } 
} 
+0

@AlexR是否爲您完成此aShot庫工作? – TitusLucretius

+0

但'Not_in_(授予它在python中)'''Java''。謝謝 – DebanjanB

+0

與Firefox控制檯中內置的「screenshot - fullpage」命令相比,aShot有點不可靠(卡在某些頁面上),而不是很好(不需要重複的'固定'元素) –

相關問題