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;它说删除未使用的进口 –