问题描述
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();
}
}
要求删除参数配置文件以匹配Eclipse中的FirefoxDriver你能帮忙解决这个问题吗?
asking to remove argument profile to match FirefoxDriver in eclipsecan you help to sort out this problem.
此行引发错误
driver = new FirefoxDriver(profile);
推荐答案
按照 FirefoxDriver 类的 Selenium JavaDoc , FirefoxDriver(配置文件)
方法不再受支持为有效的 Constructor
.
As per the Selenium JavaDoc of FirefoxDriver Class, FirefoxDriver(profile)
method is no more supported as a valid Constructor
.
鼓励使用 FirefoxOptions
类,该类扩展了 MutableCapabilities
,即 org.openqa.selenium.MutableCapabilities
Instead it is being encouraged to use the FirefoxOptions
Class which extends MutableCapabilities
i.e. org.openqa.selenium.MutableCapabilities
因此,当您通过 driver = new FirefoxDriver(profile);
在每次执行中创建新的 FirefoxProfile 时,必须使用 setProfile()< FirefoxOptions 类中的/code>方法,该方法定义为:
So as you are creating a new FirefoxProfile on each execution through driver = new FirefoxDriver(profile);
, you have to use the setProfile()
method from the FirefoxOptions Class which is defined as :
public FirefoxOptions setProfile(FirefoxProfile profile)
您的代码块将是:
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);
这篇关于无法通过FirefoxProfile参数在webdriver中使用首选项下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!