Firefox配置文件不起作用

时间:2015-05-22 10:10:00

标签: firefox selenium

以下是我的Firefox配置文件的非工作代码。

@Before

public void setUp() throws Exception {

  FirefoxProfile profile = new FirefoxProfile();

  profile.setPreference("browser.helperApps.alwaysAsk.force", false);

  profile.setPreference("browser.download.manager.showWhenStarting",false);

  profile.setPreference("browser.download.dir", "/Location");

  profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/docx");

  driver=new FirefoxDriver(profile);

  baseUrl = "<URL>";

  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test

public void test1() throws Exception {

  driver.get("URL");

  driver.findElement(By.id("Username")).sendKeys("username");

  driver.findElement(By.id("Password")).sendKeys("Password");

  driver.findElement(By.xpath(".//*[@id='rowCell0']/td[4]/a[4]")).click();// This line of code is for Download Link on the UI

现在,一旦selenium点击它,Firefox将再次打开确认框,询问&#34;打开&#34;和&#34;保存文件&#34;。

2 个答案:

答案 0 :(得分:0)

请删除       profile.setPreference(&#34; browser.helperApps.alwaysAsk.force&#34;,false);

profile.setPreference(&#34; browser.download.manager.showWhenStarting&#34;,FALSE);

并尝试它应该工作...让我知道

答案 1 :(得分:0)

我也遇到了这个问题,它阻止了我好几天! 请确保您尝试下载的文件类型,然后在下面的行中配置正确的值:

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/docx");

您的网站源代码正在发回一个内容标题,说该文件是xxx,以匹配您设置的首选项。

要引用,类型可能是:application / octet-stream,application / vnd.ms-excel,text / csv,text / plain,application / zip,application / exe,application / x-zip,application / x -zip-compressed,application / download

相关问题