-1
我正在學習selenium Webdriver。我試圖在Chrome瀏覽器上截取屏幕截圖,但我在下面的代碼中遇到了異常(注意:同一段代碼在Firefox上可用)。請幫助我在Chrome上截取屏幕截圖,並請有人解釋爲什麼下面的代碼不適用於Chrome。在Chrome瀏覽器中使用selenium webdriver截圖
public class ScreenShot
{
public static void main(String[] args) throws IOException
{
String key = "webdriver.chrome.driver";
String value = "./driver/chromedriver.exe";
System.setProperty(key, value);
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in");
TakesScreenshot screen = (TakesScreenshot) driver;
File srcFile = screen.getScreenshotAs(OutputType.FILE);
File destFile = new File("d:/google.png");
FileUtils.copyFile(srcFile, destFile);
}
}
你有什麼異常? – Thomas
打印您的堆棧跟蹤並確保yoiur chromedriver存在於該位置。 – kushal