亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 selenium webdriver 中編寫代碼以獲取此錯誤

在 selenium webdriver 中編寫代碼以獲取此錯誤

神不在的星期二 2021-08-04 15:21:47
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) 拋出異常


查看完整回答
反對 回復 2021-08-04
  • 2 回答
  • 0 關注
  • 287 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號