在 selenium webdriver 中编写代码以获取此错误

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();


}

}


神不在的星期二
浏览 253回答 2
2回答

12345678_0001

// 而不是在 FILEUTIL.cpy 文件中使用 try catch 使用该异常处理程序在 public static void main // public static void main(String[] args) 抛出异常
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java