Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method copyFile(java.io.File, java.io.File) in the type FileUtils is not applicable for the arguments (java.io.File, com.gargoylesoftware.htmlunit.javascript.host.file.File)The constructor File(String) is not visibleat DEMO.Screenshot.Homepage(Screenshot.java:37)at DEMO.Screenshot.main(Screenshot.java:47)示例代码:package DEMO;import java.io.IOException;import com.gargoylesoftware.htmlunit.javascript.host.file.File;import org.apache.commons.io.FileUtils;import org.openqa.selenium.OutputType;import org.openqa.selenium.Platform;import org.openqa.selenium.TakesScreenshot;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.remote.DesiredCapabilities;import com.gargoylesoftware.htmlunit.javascript.host.file.File;public class Screenshot {WebDriver driver;public void Homepage() { System.setProperty("webdriver.gecko.driver", "E:\\selenium_course\\geckodriver.exe"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities = DesiredCapabilities.firefox(); capabilities.setBrowserName("firefox"); capabilities.setVersion("your firefox version"); capabilities.setPlatform(Platform.WINDOWS); capabilities.setCapability("marionette", false); driver = new FirefoxDriver(capabilities); // driver=new ChromeDriver(); driver.get("https://amazon.com"); driver.manage().window().maximize(); // take screen shot and store into variable java.io.File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); // copy screen shot into local system try { FileUtils.copyFile(src, new File("E:\\selenium_course\\Screen\\homepage.png")); } catch (IOException t) { System.out.println(t.getMessage()); } driver.close();}public static void main(String[] args) { Screenshot s = new Screenshot(); s.Homepage();}}
2 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
// 而不是在 FILEUTIL.cpy 文件中使用 try catch 使用该异常处理程序在 public static void main // public static void main(String[] args) 抛出异常
添加回答
举报
0/150
提交
取消