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 visible
at 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();
}
}
12345678_0001
相关分类