1
所以我使用@Pawel_Awdmski的這個確切代碼。我得到(OutputType.FILE)下的錯誤;說FILE不能解決或不在現場。爲什麼它會給我那個錯誤?如何在不同的時間間隔在Selenium截圖並將其保存在不同的位置錯誤
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
import org.apache.commons.io.FileUtils;
import org.eclipse.jetty.server.Response.OutputType;
import org.openqa.selenium.By;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.NoSuchElementException;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import java.io.*;
public void screenShot() throws IOException, InterruptedException
{
File scr=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File dest= new File("filPath/screenshot_"+timestamp()+".png");
FileUtils.copyFile(scr, dest);
Thread.sleep(3000);
}
public string timestamp() {
return new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date());
}
沒有能夠看到所有的代碼,我說你已經導入了錯誤的'OutputType'或忘記導入它在所有。 'import org.openqa.selenium.OutputType;' – PizzaFrog
你必須導入'import java.io.File;或者導入java.io。*;'類的頂部。 – gihan
我現在更新我的導入。我仍然得到錯誤。當我嘗試iimport org.openqa.selenium.OutputType;它說刪除未使用的進口 –