升级后,设置chrome驱动程序的下载目录突然停止工作

时间:2017-11-16 23:41:31

标签: selenium-webdriver selenium-chromedriver

在我升级项目以使用最新的java selenium webdriver 3.7.1和最新的chrome驱动程序2.33后,我注意到我处理Excel导出的测试开始失败。

调试后我发现由于某些原因,下载目录没有设置为自定义位置,而是使用默认位置。没有任何东西出现在日志中或无论如何。

任何帮助表示感谢。

设置下载目录就像平常一样:

    val prefs = Map(
      "profile.default_content_settings.popups" -> Integer.valueOf(0),
      "download.default_directory" -> downloadsDir,
      "credentials_enable_service" ->  false,
      "profile.password_manager_enabled" -> false
    )
    val chromeOptions:ChromeOptions = new ChromeOptions()
    chromeOptions.setExperimentalOption("prefs", prefs)
    val d = new ChromeDriver(chromeOptions)

1 个答案:

答案 0 :(得分:0)

我使用的是WebDriver 3.7.1和Chromedriver 2.33,当然还有Chrome v.62(请检查您的Chrome版本),我可以下载文件。

我正在使用文件夹

public static String javaIoTmpDir = System.getProperty("java.io.tmpdir")+"/autotest/";

我用TestNG注释中的脚本创建/清理它:@BeforeSuite

File theDir = new File(javaIoTmpDir);
    // if the directory does not exist, create it
    if (!theDir.exists()) {
        System.out.println("creating directory: " + theDir.getName());
        boolean result = false;
        try{
            theDir.mkdir();
            result = true;
        }
        catch(SecurityException se){
            se.printStackTrace();
        }
        if(result) {
            System.out.println(javaIoTmpDir+" created");
        }
    }
        FileUtils.cleanDirectory(new File(javaIoTmpDir));
    }
相关问题