Java 无法在webdriver中传递FirefoxProfile参数以使用首选项下载文件

Java 无法在webdriver中传递FirefoxProfile参数以使用首选项下载文件,java,selenium,mutablecapabilities,Java,Selenium,Mutablecapabilities,请求删除参数配置文件以匹配eclipse中的FirefoxDriver 你能帮我解决这个问题吗 此行上抛出错误 public class download { public static WebDriver driver; public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.gecko.driver", "/home

请求删除参数配置文件以匹配eclipse中的FirefoxDriver 你能帮我解决这个问题吗

此行上抛出错误

public class download {
    public static WebDriver driver;

    public static void main(String[] args) throws InterruptedException {

        System.setProperty("webdriver.gecko.driver", "/home/ranjith/Downloads/geckodriver");
        //driver = new FirefoxDriver();

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("browser.download.dir", "/home/ranjith/Downloads");
        profile.setPreference("browser.download.folderList", 2);

        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");        
        profile.setPreference( "browser.download.manager.showWhenStarting", false );
        profile.setPreference( "pdfjs.disabled", true );

        driver = new FirefoxDriver(profile); 

        driver.get("http://toolsqa.com/automation-practice-form/");
        driver.findElement(By.linkText("Test File to Download")).click();

        Thread.sleep(5000);

        //driver.close();
    }
}
根据FirefoxDriver类的Selenium JavaDoc,
FirefoxDriver(profile)
方法不再作为有效的
构造函数受支持

相反,我们鼓励使用
FirefoxOptions
类,该类扩展了
MutableCapabilities
,即
org.openqa.selenium.MutableCapabilities

因此,当您在每次执行时通过
driver=newfirefoxdriver(profile)创建新的FirefoxProfile时
,必须使用FirefoxOptions类中的
setProfile()
方法,该类定义为:

driver = new FirefoxDriver(profile); 
您的代码块将是:

public FirefoxOptions setProfile(FirefoxProfile profile)

Hi Ranjith请说明您需要什么,以及您试图实现什么,因为FireFoxDriver类中没有接受自定义类作为参数的构造函数,这就是您面临该错误的原因清除
浏览器缓存
,运行
CCleaner
工具以清除所有操作系统杂务。重新启动
系统
并运行
测试
,然后告诉我状态。实际上,我正在尝试使用selenium webdriver下载文件。现在,在解决了所有问题后,它开始工作
System.setProperty("webdriver.gecko.driver", "/home/ranjith/Downloads/geckodriver");
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "/home/ranjith/Downloads");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");        
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference( "pdfjs.disabled", true );
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(profile);
driver = new FirefoxDriver(opt);